forked from wbhima/CodeforALL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_calculator.cpp
51 lines (44 loc) · 986 Bytes
/
simple_calculator.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
50
51
#include <iostream>
using namespace std;
int main()
{
char op;
double num1, num2;
cout<<"Enter operator(+,-,*,/) - "<<endl;
cin>>op;
cout<<"Enter two numbers- "<<endl;
cin>>num1>>num2;
switch(op)
{
case '+':
{
cout<<num1<<" + "<<num2<<" = "<<(num1+num2)<<endl;
break;
}
case '-':
{
cout<<num1<<" - "<<num2<<" = "<<(num1-num2)<<endl;
break;
}
case '*':
{
cout<<num1<<" * "<<num2<<" = "<<(num1*num2)<<endl;
break;
}
case '/':
{
if(num2 ==0){
cout<<"Invalid operation"<<endl;
}
else{
cout<<num1<<"/"<<num2<<" = "<<(num1/num2)<<endl;
break;
}
}
default:
{
cout<<"Invalid operator"<<endl;
}
}
return 0;
}