In the following code, why must int nInteger
be declared inside int readNumber()
's body, but int nAnswer
must be declared inside the () portion of void writeAnswer()
? Declaring int nInteger
inside the () or declaring int nAnswer
inside the function body causes the IDE to complain about too few arguments for said function. Why does this happen?
I'm using Code::Blocks and the included MinGW on a Windows 7.
#include <iostream>
int readNumber()
{
using namespace std;
cout << "Please enter an integer: ";
int nInteger;
cin >> nInteger;
return nInteger;
}
void writeAnswer(int nAnswer)
{
using namespace std;
cout << "The sum is: " << nAnswer << endl;
}
int main()
{
int x;
int y;
x = readNumber();
y = readNumber();
writeAnswer(x+y);
return 0;
}