When you have "int" next to the variable name, that means you're trying to declare a variable. You do this correctly on line 16.
But on line, 17, x is now an already-existing variable, so you should just pass x.
But all of that aside, please realise that there is no point in even passing the variable x into your test function, actually, because it's immediately overwritten by the
cin >> x;
I would suggest looking up the term "scope" for C++. The variable called x inside of your test function is
local to that function. In other words, the x declared in main() has nothing to do with the x declared in test().
Since you are returning a value from your test function, you should have a way to save that variable.
Try this instead:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
using namespace std;
int test()
{
int x;
cin >> x;
return x;
}
int main()
{
int x;
x = test();
cout << x << endl;
system("PAUSE");
return 0;
}
|
Let me know if I can make anything I said clearer.