-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2_simple_calculator.cpp
More file actions
54 lines (49 loc) · 1.56 KB
/
task2_simple_calculator.cpp
File metadata and controls
54 lines (49 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
#include <iostream>
using namespace std;
int main() {
double num1, num2;
int choice;
do {
cout << "TASK 2 - SIMPLE CALCULATOR" << endl;
cout << "\nSimple Calculator" << endl;
cout << "Select operation:" << 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 (1/2/3/4/5): ";
cin >> choice;
if (choice >= 1 && choice <= 4) {
cout << "Enter first number: ";
cin >> num1;
cout << "Enter second number: ";
cin >> num2;
}
switch(choice) {
case 1:
cout << "Result: " << num1 + num2 << endl;
break;
case 2:
cout << "Result: " << num1 - num2 << endl;
break;
case 3:
cout << "Result: " << num1 * num2 << endl;
break;
case 4:
if (num2 != 0) {
cout << "Result: " << num1 / num2 << endl;
} else {
cout << "Error: Division by zero is not allowed." << endl;
}
break;
case 5:
cout << "Exiting the program." << endl;
break;
default:
cout << "Error: Invalid choice. Please select a number between 1 and 5." << endl;
break;
}
} while (choice != 5);
return 0;
}