### Function calculator

I got a problem here.
Make your calculator program perform computations in a separate function for each type of computation

 ``1234567891011121314151617181920212223242526272829303132`` ``````int plus(int y,int x) { return x+y; } int minus(int y,int x) { return x-y; } int divide(int y,int x) { if(x=0) { cout<<"error"; //cannot divide by 0 } else { return x/y; } } int times(int y,int x) { return x*y; } int main() { int val1,val2; cout<>val1>>val2; cout<

can someone correct this codes?
line 11 needs 2 equals. you're using the assignment operator at the moment.
I think you need to test for y equalling zero not x.

also you're doing integer division so you're answer will be truncated.

line 30. You do not call functions like this. See:
http://www.cplusplus.com/doc/tutorial/functions/
hello mutexe thank you but it was not my problem

line 30 i dont really get it :(
he means they are functions so need calling like that...
`cout<<plus(val1,val2)<<times(val1,val2)<<divide(val1,val2)<<times(val1,val2);`

`error: reference to 'plus' is ambiguous `

can you correct the code and explain it to me please
You have probably just first-hand encountered the problems of having using namespace std in your code. std::plus already exists as a function taking two arguments, while you have provided another possibility for the call, hence the ambiguity of the call. If you instead remove that line and fully qualify your statements, you won't run across that problem later. Try something like this:
 ``12345678910111213141516171819202122`` ``````#include int plus(int a, int b) { return a + b; } // etc. etc. etc. int main() { int val1; int val2; std::cout << "Enter two numbers: "; std::cin >> val1 >> val2; std::cout << plus(val1, val2) << ' ' << minus(val1, val2) << ' ' << times(val1, val2) << ' ' << divide(val1, val2) << '\n'; return 0; }``````

What else do you need explaining?
Last edited on
 but it was not my problem

line 11 IS a problem.

 can you correct the code and explain it to me please