Operations on a switch statement

¡Hi guys, I am trying to figure out if I can do operations inside the switch statements since I am trying to do a Calculator program I don't know how to make the computer to understand that the operation that I'm trying to do is the character that I'm inputting called oper is inputting.

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
#include <iostream>
using namespace std;

int main ()
	{
		char oper;
		float num1,num2;
		cout<<"Please enter first number,operator & second number: ";
		cin>>num1>>oper>>num2;
		switch(oper)
			{
			case 1:oper = num1 * num2 ;
			    cout<<"The sum is "<<oper;
			    break;
			case 2: oper = num1 - num2;
			    cout<<"The difference is "<<oper;
			    break; 
			case 3: oper = num1 * num2;
			    cout<<"The product is "<<oper;
			    break;
			case 4: oper = num1 / num2;
			    cout<<"The reminder is "<<oper;
			    break;
			default: cout<<"invalid number";
			    break; 
			}
			
	cin.ignore();
	cin.get();
    return 0; 
	}
Last edited on
Topic archived. No new replies allowed.