help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

help

when I subtract comes up with a random number but when I add it comes with the right answer please help me #include <iostream> using namespace std; int main() { int a; int b; int sym; int sum; int sub; cout<<"put numder\n"; cin>> a; cout<<"put another number\n"; cin>> b; cout<<"are you adding(1) or subtrating(2) \n"; cin>> sym; cout<<"output\n"; if (sym = sum){ sum = a + b; cout<< sum; } if(sym = sub){ sub = a - b; cout<<sub; } return 0; }

2nd Sep 2016, 3:58 AM
Matthew R.
3 Answers
+ 2
sym is of int data type. It can accept integer data. So for addition it must accept 1 and for subtraction it must take 2 as input. In the condition checking for calculation make it if(sym ==1) for addition and if(sym==2) for subtraction.
2nd Sep 2016, 4:06 AM
Shark riding Astronaut
Shark riding Astronaut - avatar
+ 1
nice programs
7th Sep 2016, 7:12 AM
தனுராஜ் ராஜ் தனுராஜ்
தனுராஜ் ராஜ் தனுராஜ் - avatar
0
thanks I forgot that have to put two =
2nd Sep 2016, 4:38 AM
Matthew R.