-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculator.cpp
58 lines (41 loc) · 955 Bytes
/
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
52
53
54
55
56
57
#include<iostream>
using namespace std;
int main (){
char oper;
int n1,n2,calculatedNum;
cout<<"Menu"<<endl;
cout<<"_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "<<endl;
cout<<"+ Addition"<<endl;
cout<<"- Subtraction"<<endl;
cout<<"* Multiplication"<<endl;
cout<<"/ Division"<<endl;
cout<<". Cancel"<<endl;
cout<<"Pick the operator you want"<<endl;
cin>>oper;
cout<<"Enter the first number"<<endl;
cin>>n1;
cout<<"Enter the second number"<<endl;
cin>>n2;
switch(oper){
case '+':
calculatedNum = n1 + n2;
cout<<n1<<oper<<n2<<" = "<<calculatedNum;
break;
case '-':
calculatedNum = n1 - n2;
cout<<n1<<oper<<n2<<" = "<<calculatedNum;
break;
case '*':
calculatedNum = n1 * n2;
cout<<n1<<oper<<n2<<" = "<<calculatedNum;
break;
case '/':
calculatedNum = n1 / n2;
cout<<n1<<oper<<n2<<" = "<<calculatedNum;
break;
case '.':
default :
cout<<"Cancelling Program";
}
return 0;
}