I just started c++ Today. I have been working on a simple calculator. When i leave out all if statements but 1, it works fine. When I put in other if statements i get really weird numbers like 3*3=6
heres my code.
#include <iostream>
usingnamespace std;
int main()
{
int a,b,c;
cout <<"CALC V.1 ||| Press enter to continue";
cin.ignore();
cout <<"1=+ 2=- 3=* 4=/ ";
cout <<"Please enter an arithmetic operator: ";
cin>>a;
cout <<"Please enter a number: ";
cin>>b;
cout <<"Please enter a number :";
cin>>c;
cout <<"press enter to continue""\n";
cin.ignore();
if (a==1);
{cout << b+c;};
if (a==2);
{cout << b-c;};
if (a==3);
{cout << b*c;};
if (a==4);
{cout << b/c;};
return 0;
}
When i take out the other 3 if statements, it works fine. But when I add the rest in i get the weird numbers. Can someone help?
You have too many ;. If statements aren't supposed to have one after them, and { } sections don't need them. Also, I would suggest indenting your code there: