-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleCalculator.cpp
76 lines (55 loc) · 1.62 KB
/
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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
// main.cpp
// calculator
//
// Created by Martin Kalliola on 16.11.2020.
//
#include <iostream>
using namespace std;
int main() {
char op;
float num1, num2;
bool flag = true;
while (flag == true) {
cout << "Please type the operator: ";
cin >> op;
if (op == 'q') {
cout << "Thank you for using my SimpleCalculator" << endl;
flag = false;
}
else if (op == '-' || op == '+' || op == '*' || op == '/') {
cout << "Type the first number ";
cin >> num1;
if (cin.fail()) {
cout << "Numbers only plzz" << endl;
cin.clear();
}
cout << "Type the second number ";
cin >> num2;
if (cin.fail()) {
cout << "Numbers only plzz" << endl;
cin.clear();
}
switch (op) {
case '+':
cout << "The result is: " << num1 + num2 << endl;
break;
case '-':
cout << "The result is: " << num1 - num2 << endl;
break;
case '/':
if (num2 != 0)
cout << "The result is: " << num1 / num2 << endl;
else
cout << "Error, cannot divide by 0" << endl;
break;
case '*':
cout << "The result is: " << num1 * num2 << endl;
break;
default:
cout << "Error, big error... Nothing to calculate.";
break;
}
}
}
return 0;
}