Simple calculator question

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  #include <iostream>
#include <stdio.h>
using namespace 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:
Last edited on
Morning,
You are missing a break keyword at the end of each case.

See the section on switch here:
http://www.cplusplus.com/doc/tutorial/control/
@mutexe
thanks it works like a charm
Topic archived. No new replies allowed.