-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.cpp
44 lines (38 loc) · 854 Bytes
/
calc.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
/*
Create a calculator using switch statement to perform addition,subtraction,multiplication and division.
Sample Input :
Enter an operator(+,-,*,/): -
Enter two numbers :
6
8
Sample Output : 6 - 8 = -2
*/
#include <iostream>
using namespace std;
int main()
{
char ch;
float a, b;
cout << "Enter an operator : " << ch;
cin >> ch;
cout << "Enter two numbers : ";
cin >> a >> b;
switch (ch)
{
case '+':
cout << a << " + " << b <<" = "<< a + b;
break;
case '-':
cout << a << " - " << b <<" = "<< a - b;
break;
case '*':
cout << a << " * " << b <<" = "<< a * b;
break;
case '/':
cout << a << " / " << b <<" = "<< a / b;
break;
default:
cout<<"Not a valid operator thats why calculator cannot perform";
break;
}
}