#Can you help me figure out the error
12 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
here is the error msg
the third time it did start 
!format
#include <iostream>
int add() {
return x + y;
}
void printresult(int z) {
std::cout << "the answer is : " << z << "\n";
}
int getuserinput() {
std::cout << "enter a number";
int x{};
std::cin >> x;
return x;
}
int main() {
int x{getuserinput()};
int y{getuserinput()};
int z{add(x, y)};
printresult(z);
}
;compile
Compiler Output
<source>: In function 'int add()':
<source>:3:10: error: 'x' was not declared in this scope
3 | return x + y;
| ^
<source>:3:14: error: 'y' was not declared in this scope
3 | return x + y;
| ^
<source>: In function 'int main()':
<source>:17:12: error: too many arguments to function 'int add()'
17 | int z{add(x, y)};
| ~~~^~~~~~
<source>:2:5: note: declared here
2 | int add() {
| ^~~
Build failed
phaseshift. | c++ | x86-64 gcc 14.2 | godbolt.org
There, now the errors are clear
try passing x and y to the add function e.g. int add(int x, int y) { return x + y } for the declaration and int z = add(x, y); for the reference.
then declare your variable and assign it the user input you like such as:
int x = getuserinput(); the rest of the errors are similar.
bc ur not passing the x and y to the add function
u don't have a variable to store that value u pass