-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple calculator
More file actions
51 lines (44 loc) · 1.02 KB
/
Copy pathsimple calculator
File metadata and controls
51 lines (44 loc) · 1.02 KB
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
// a simple calculator
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"Welcome to my Calculator :)\n";
int op1,op2;
cout<<"enter two numbers: ";
cin>>op1>>op2;
// add
int sum=op1+op2;
// sub
int sub=op1-op2;
// mul
int mul=op1*op2;
// div
int divi=op1/op2;
// mod
int mod=op1%op2;
int choice;
cout<<"select the option from(1,2,3,4,5):\n1->add\n2->sub\n3->mul\n4->div\n5->mod:\n\nThe option: ";
cin>>choice;
switch(choice){
case 1:
cout<<sum<<endl;
break;
case 2:
cout<<sub<<endl;
break;
case 3:
cout<<mul<<endl;
break;
case 4:
cout<<divi<<endl;
// if(op1/0){
// cout<<"Error trying to div by zero";
// }
break;
case 5:
cout<<mod<<endl;
break;
default:
cout<<"Invalid option"<<endl;
}
}