-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (34 loc) · 981 Bytes
/
Copy pathmain.cpp
File metadata and controls
35 lines (34 loc) · 981 Bytes
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
//Switch simple code to understand break, continue, and switch
#include <iostream>
using namespace std;
int result;
char op_char;
int number;
int main() {
int result = 10;// initialize result to smth to work with
while (true) {
cout << "Enter operator and number";
cin >> op_char >> number;
if ((op_char == 'q') || (op_char == 'Q'))
break;// break terminates
switch (op_char) {
case '+':
result += number;
break;
case '-':
result -= number;
break;
case '*':
result *= number;
break;
case '/':
result /= number;
break;
default:
cout << "Unknown operator" << op_char << '\n';
continue;// continue goes to the beginning of the switch
}
cout << "Result: " << result << '\n';
}
return 0;
}