I've been trying to make just a basic calculator.
The problem is at line 33 where i expected WriteAnswer to write the variable 'ans' but it did not.
What am I doing wrong?
#include <iostream>
usingnamespace std;
int ReadNumber(){
cout << "enter first number:" << endl;
int fNum;
cin >> fNum;
cout << "enter second number:" << endl;
int sNum;
cin >> sNum;
int ans(fNum + sNum);
return ans;
}
void WriteAnswer(){
int ans;
cout << "The sum is:" << ans << endl;
}
int main() {
int fNum;
int sNum;
WriteAnswer(fnum + sNum);
return 0;
}
#include <iostream>
usingnamespace std;
int ReadNumber(){
cout << "enter first number:" << endl;
int fNum;
cin >> fNum;
cout << "enter second number:" << endl;
int sNum;
cin >> sNum;
int ans(fNum + sNum);
return ans;
}
void WriteAnswer(int ans){
cout << "The sum is:" << ans << endl;
}
int main() {
int fNum;
int sNum;
WriteAnswer(fNum + sNum);
return 0;
}
At line 33 you wrote 'fnum', not the same with 'fNum',C++ is case sensitive.
At line 33 you are passing an integer to the function,but the function has no parameters.So modify it's definition,and print the passed value.
You are not initializing fNum and sNum.
#include <iostream>
usingnamespace std;
int ReadNumber(){
cout << "enter first number:" << endl;
int fNum;
cin >> fNum;
cout << "enter second number:" << endl;
int sNum;
cin >> sNum;
int ans(fNum + sNum);
return ans;
}
void WriteAnswer(int ans){
int ans;
cout << "The sum is:" << ans << endl;
}
int main() {
int fNum;
int sNum;
WriteAnswer( ReadNumber() );
return 0;
}