-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch_1.cpp
122 lines (114 loc) · 2.22 KB
/
switch_1.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include<iostream>
using namespace std;
// int main(){
// int a;
// cin>>a;
// switch(a){
// case 1:
// cout<<"31";
// break;
// case 2:
// cout<<"28";
// break;
// case 3:
// cout<<"31";
// break;
// case 4:
// cout<<"30";
// break;
// case 5:
// cout<<"31";
// break;
// case 6:
// cout<<"30";
// break;
// case 7:
// cout<<"31";
// break;
// case 8:
// cout<<"31";
// break;
// case 9:
// cout<<"30";
// break;
// case 10:
// cout<<"31";
// break;
// case 11:
// cout<<"30";
// break;
// case 12:
// cout<<"31";
// break;
// default:
// cout<<"please enter the correct month number";
// break;
// }
// return 0;
//*********negative positive or zero**********
// int main(){
// int n;
// cout<<"enter the number:";
// cin>>n;
// if (n>0)
// n=1;
// else if (n<0)
// n=2;
// else
// n=3;
// switch(n){
// case 1:
// cout<<"positive";
// break;
// case 2:
// cout<<"negative";
// break;
// case 3:
// cout<<"zero";
// break;
// }
// }
//***********simple calculator using switch case************
int main(){
cout<<"following operations are to be performed; Please choose;"<<endl;
cout<<"addition +"<<endl;
cout<<"subtraction -"<<endl;
cout<<"multiplication *"<<endl;
cout<<"diviison /"<<endl;
cout<<"modulus %"<<endl;
int a,b,m;
char o;
cin>>a>>o>>b;
if (o=='+')
m=1;
else if (o=='-')
m=2;
else if (o=='*')
m=3;
else if(o=='/')
m=4;
else if (o=='%')
m=5;
else
m=0;
switch(m){
case 1:
cout<<a+b;
break;
case 2:
cout<<a-b;
break;
case 3:
cout<<a*b;
break;
case 4:
cout<<a/b;
break;
case 5:
cout<<a%b;
break;
default:
cout<<"enter the correct operation;";
break;
}
}