Calculator doesn't work

Is there a problem with my code? It is supposed to be a calculator with 3 operators only. It's for an assignment.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
int main() {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op = '+') cout << a+b;
    if (op = '-') cout << a-b;
    if (op = '*') cout << a*b;
    return 0;
}
= != ==
In case you don't get it, in your if statements, you can't use a single "=" sign, you need either a double "==" which means is equal to, or "!=" which means is not equal to.
Topic archived. No new replies allowed.