use cout inside a function

How can I use cout inside a function to print out?
1
2
3
4
5
6
7
8
9
10
11
 #include <iostream>
using namespace std;

void Print(){
    cout << "Print this out ";
}


int main() {
        void Print();
}
Last edited on
On line 10, you accidentally declare the function when you actually meant to call the function. Remove the word void from line 10.
Make a function take 2 arguments and call it;

error: expected primary-expression before 'double' MaxorMin(int n, double x);


#include <iostream>
using namespace std;

void MaxorMin(int n, double x){
cout << "Type two numbers: ";
cin >> n >> x;
}


int main() {
MaxorMin(int n, double x);
}
Last edited on
Please review how functions work:
http://www.cplusplus.com/doc/tutorial/functions/
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

void MaxorMin(int n, double x){
cout << "Tyoe two numbers: ";
cin >> n >> x;
}


int main() {
MaxorMin(int n, double x);
}


I dont think you really know how functions work yet. When you're calling for the MaxMin function, which takes 1 integer, and one double as paramters. You're supposed to give it those parameters.

MaxorMin(int n, double x); // not in this way

But something like this - MaxorMin(5, 3.4);

Or this -

1
2
3
4
int x = 10; 
double y = 2.33;

MaxorMin(x, y);


Take a look at these 2 c++ tutorial playlists, and look for the function videos -
Bucky: https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83
C++ Made Easy: https://www.youtube.com/playlist?list=PL2DD6A625AD033D36
Topic archived. No new replies allowed.