-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator#2.cpp
More file actions
63 lines (53 loc) · 1.56 KB
/
calculator#2.cpp
File metadata and controls
63 lines (53 loc) · 1.56 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
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
char choice;
do {
cout << "Simple Calculator Menu:" << endl;
cout << "1. Addition" << endl;
cout << "2. Subtraction" << endl;
cout << "3. Multiplication" << endl;
cout << "4. Division" << endl;
cout << "5. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
if (choice == '5') {
break;
}
double firstValue, secondValue;
cout << "Enter the first value: ";
cin >> firstValue;
char op;
cout << "Enter the operator (+, -, *, /): ";
cin >> op;
cout << "Enter the second value: ";
cin >> secondValue;
double result;
switch (op) {
case '+':
result = firstValue + secondValue;
break;
case '-':
result = firstValue - secondValue;
break;
case '*':
result = firstValue * secondValue;
break;
case '/':
if (secondValue != 0) {
result = firstValue / secondValue;
} else {
cout << "Division by zero is not allowed." << endl;
continue;
}
break;
default:
cout << "Invalid operator: " << op << endl;
continue;
}
cout << "Result: " << result << endl;
} while (true);
return 0;
}