-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5th-calculator.cpp
More file actions
35 lines (29 loc) · 920 Bytes
/
5th-calculator.cpp
File metadata and controls
35 lines (29 loc) · 920 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
#include <iostream>
using namespace std;
int main() {
double num1, num2;
char operation;
cout << "Enter the first number: ";
cin >> num1;
cout << "Enter the second number: ";
cin >> num2;
cout << "Select the Operation (+, -, *, /): ";
cin >> operation;
// Calculating based on the operator
if (operation == '+') {
cout << "Result: " << num1 + num2 << endl;
} else if (operation == '-') {
cout << "Result: " << num1 - num2 << endl;
} else if (operation == '*') {
cout << "Result: " << num1 * num2 << endl;
} else if (operation == '/') {
if (num2 != 0) {
cout << "Result: " << num1 / num2 << endl;
} else {
cout << "Division by zero is not allowed." << endl;
}
} else {
cout << "Invalid operator." << endl;
}
return 0;
}