how to make a calculator for beginners

#include<iostream>
using namespace std;

void calc()
{
int a;
int b;
string opp;

cout << "enter value of a";
cin >> a;
cout << "enter value of b";
cin >> b;
cout << "select operator";
cin >> opp;

if (opp ="+"){
cout << a+b;
} if (opp="-"){
cout << a-b;
}if (opp="/"{
cout << a/b;
}if (opp="*"){
cout << a*b;
}
}

int main()
{
calc();
return 0;
}
Not sure if you were having trouble with this but just wanted to point out a couple of things I noticed.

On your if statements, if you're comparing the values of two items, you need the equality operator ==, not the assignment operator =.

With the division, you might want to check the value entered for b to make sure you don't end up dividing by zero and crashing.

Dividing two integers will also give you an integer division result - if someone enters 5 for a and 3 for b, they might not expect to get 1. You'll need to tweak the code a little bit if you want them to get a floating point result.

}if (opp="/"{ <- missing a closing ) there :)
b=0
Topic archived. No new replies allowed.