#Can you help me figure out the error

12 messages · Page 1 of 1 (latest)

foggy coral
#

#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);
}

thorny hornetBOT
#

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.

foggy coral
#

here is the error msg

gilded phoenix
#

the third time it did start yamikek

thorny hornetBOT
#
#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);
}
ZAZh
tacit oasisBOT
#
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
sullen timber
#

There, now the errors are clear

idle apex
#

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.

primal sky
#

u don't have a variable to store that value u pass