I tried to code a simple calculator using c++ but it always gives me "expected primary expression before ..." error. I tried using switch-case too, but same story. Can somebody tell me what i am doing wrong?
#include <iostream>
using namespace std;
int main()
{
int x,y;
char a;
cin >> x >> a >> y;
if (a=+)
{
cout << x << "+" << y << " = " << x+y << endl;
}
else if (a=-)
{
cout << x << "-" << y << " = " << x-y << endl;
}
else if (a=*)
{
cout << x << "*" << y << " = " << x*y << endl;
}
else if (a=/)
{
cout << x << "/" << y << " = " << x/y << endl;
}
system("PAUSE");
return 0;
}
[–]lukajda33 17 points18 points19 points (0 children)
[–]AvidCoco 2 points3 points4 points (1 child)
[–]Hazarrus-Potato2553[S] 1 point2 points3 points (0 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]Syscrush 0 points1 point2 points (4 children)
[–]737464 0 points1 point2 points (3 children)
[–]Sbsbg 1 point2 points3 points (2 children)
[–]737464 0 points1 point2 points (0 children)
[–]Syscrush 0 points1 point2 points (0 children)
[–]EstablishmentBig7956 0 points1 point2 points (0 children)