-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.cpp
More file actions
45 lines (38 loc) · 1.15 KB
/
calculator.cpp
File metadata and controls
45 lines (38 loc) · 1.15 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>
int main() {
char op;
double num1, num2;
std::cout << "* * * * * * * * * * * * Calculator * * * * * * * * * * * *" << std::endl;
std::cout << "Enter the first number: ";
std::cin >> num1;
if(!num1) {
std::cout << "Number 1 is not valid" << std::endl;
return 1;
}
std::cout << "Enter the second number: ";
std::cin >> num2;
if(!num2) {
std::cout << "Number 2 is not valid" << std::endl;
return 1;
}
std::cout << "Enter the operator (+, -, *, /): ";
std::cin >> op;
switch (op) {
case '+':
std::cout << "Result: " << num1 + num2 << std::endl;
break;
case '-':
std::cout << "Result: " << num1 - num2 << std::endl;
break;
case '*':
std::cout << "Result: " << num1 * num2 << std::endl;
break;
case '/':
std::cout << "Result: " << num1 / num2 << std::endl;
break;
default :
std::cout << "This calculator can only handle +, -, *, / operations" << std::endl;
break;
}
return 0;
}