-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_switch_math.cpp
49 lines (40 loc) · 1.07 KB
/
basic_switch_math.cpp
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
45
46
47
48
49
#include <iostream>
#include<iomanip>
using namespace std;
int main ()
{
double a;
double b;
char c;
double result;
string deF;
cout << "Enter a number:" << endl;
cin >> a;
cout << "Enter another number:" << endl;
cin >> b;
cout << "Enter an operator:" << endl;
cin >> c;
cout << fixed << setprecision(2);
switch (c)
{
case '+':
result = a + b;
cout << a << " " << c << " " << b << " " << "=" << " " << result << endl;
break;
case '-':
result = a - b;
cout << a << " " << c << " " << b << " " << "=" << " " << result << endl;
break;
case '*' :
result = a * b;
cout << a << " " << c << " " << b << " " << "=" << " " << result << endl;
break;
case '/':
result = a / b;
cout << a << " " << c << " " << b << " " << "=" << " " << result << endl;
break;
default:
deF = "Invalad operator!";
cout << deF;
}
}