So i am trying to build this simple calculator that tells you if you have entered a wrong operator and that asks you if you want to do another calculation after completing the first. Everything works fine except for that when i want to do a subtraction for example the calculator thinks i want to do a multiplication
#include <iostream>
#include <stdio.h>
usingnamespace std;
int main ()
{
char oper;
float a,b,c,i=1;
while (i==1)
{
a=0;
b=0;
c=0;
fflush(stdin);
cout<<"Choose one (+,-,*,/)";
oper=getchar();
if (oper=='+'||oper=='-'||oper=='*'||oper=='/')
{
cout<<"Enter the first number:";
cin>>a;
cout<<"Enter the second number:";
cin>>b;
switch (oper)
{
case'+':
c=a+b;
case'-':
c=a-b;
case'/':
c=a/b;
case'*':
c=a*b;
}
printf( "The answer is:""%.2f",c);
cout<<"\nFor a new calculation enter 1, to exit enter 2:";
cin>>i;
}
else {
i=1;
cout<<"Wrong operator!\n";
}
}
return 0;
}
This is what happens:
Chose one(+,-,/,*):-
Enter the fist number:5
Enter the second number:3
The answer is:15.00
For a new calculation enter 1, to exit enter 2: