-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleCalculator.cpp
36 lines (32 loc) · 1004 Bytes
/
SimpleCalculator.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
#include <iostream>
using namespace std;
int main() {
cout << "SIMPLE CALCULATOR" << endl << endl;
while (true) {
int a, b;
char op;
cout << "Enter the operation (e.g., 5 + 3): ";
cin >> a >> op >> b;
switch (op) {
case '+':
cout << "ANSWER = " << a + b << endl << endl;
break;
case '-':
cout << "ANSWER = " << a - b << endl << endl;
break;
case '*':
cout << "ANSWER = " << a * b << endl << endl;
break;
case '/':
if (b != 0) {
cout << "ANSWER = " << a / b << endl << endl;
} else {
cout << "Error: Division by zero is not allowed." << endl << endl;
}
break;
default:
cout << "Invalid operation. Please use +, -, *, or /." << endl << endl;
}
}
return 0;
}