-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path33-switch-case-tut.cpp
44 lines (28 loc) · 984 Bytes
/
33-switch-case-tut.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
// tutorial for `case` in c++
#include <iostream>
using namespace std;
int main (){
int a, b, opr;
cout << "Enter two space-separated integers: "; cin >> a >> b;
cout << "Enter which operation you want perform:\n1 for add\n2 for substract\n3 for divide\n4 for multiply\n>>> ";
cin >> opr;
switch(opr){
case 1 :
cout << "The sum is: " << a + b;
break; // `break` is super IMPORTANT! it prevents below lines from operating.
case 2 :
cout << "The difference is: " << a - b;
break;
case 3 :
cout << "The quotient is: " << a / b;
break;
case 4:
cout << "The product is: " << a * b;
break;
default :
cout << "Wrong Input.";
return 0;
}
return 0;
}
// Mohammad Maasir | 9 sep 2023 | 20:02