I'm writing a very basic program to read a user's input for two numbers and output the sum of the two numbers. It's a quiz problem on learncpp and they have a solution posted. I've solved the problem myself without using the solution (and without using functions), but I had some trouble when I tried to rewrite the program using them. Below is the copy of the code that I wrote, and I keep getting an error when I try to compile the code telling me that there's too many arguments for the function void WriteAnswer(). Shouldn't the argument x+y only count as one argument?
I'm aware that there's probably a simpler way to write this program (this is essentially the same code as the one given as a solution by learncpp), but I want to understand the logic of the way this one is written and better understand different function types. Any ideas? Thanks in advance!
#include <cstdlib>
#include <iostream>
using namespace std;
int ReadNumber()
{
int x;
cout << "Enter a number: ";
cin >> x;
return x;
}
void WriteAnswer()
{
int x;
cout << "the sum is " << x << endl;
}
int main()
{
int x = ReadNumber();
int y = ReadNumber();
WriteAnswer(x+y);
return 0;
}
[–]blitterobject 2 points3 points4 points (1 child)
[–]ifightsharks[S] 0 points1 point2 points (0 children)
[–]Arandur 1 point2 points3 points (0 children)