-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.cpp
More file actions
45 lines (38 loc) · 1.17 KB
/
Copy pathswitch.cpp
File metadata and controls
45 lines (38 loc) · 1.17 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
#include <iostream>
using namespace std;
int main() {
char operation;
double number1, number2;
while (true) {
cout << "Enter the operation (+, -, *, /) or 'q' to quit: ";
cin >> operation;
if (operation == 'q') {
cout << "Goodbye!";
break;
}
cout << "Enter the first number: ";
cin >> number1;
cout << "Enter the second number: ";
cin >> number2;
switch (operation) {
case '+':
cout << "Result = " << number1 + number2 << endl;
break;
case '-':
cout << "Result = " << number1 - number2 << endl;
break;
case '*':
cout << "Result = " << number1 * number2 << endl;
break;
case '/':
if (number2 != 0)
cout << "Result = " << number1 / number2 << endl;
else
cout << "Error: Division by zero!" << endl;
break;
default:
cout << "Invalid operation!" << endl;
}
}
return 0;
}