0
I tried to improve upon my calculator design, why isn't this working?
#include <iostream> using namespace std; int main() { int o; int a; int b; int sum; if(o = 1) { sum= a*b; } if(o = 2){ sum= a+b; } if(o = 3) { sum= a/b; } if(o = 4) { sum= a-b; } cin >> o; cin >> a; cin >> b; cout << sum; return 0; }
2 Respostas
+ 5
The if statements should be placed after the user gives the variables values with the cin statements, and before the cout.
It isn't working because the variables in the ifs aren't given values yet, and contain random garbage.
0
Ah, thanks! I'll try it again.