-
Notifications
You must be signed in to change notification settings - Fork 51
/
BasicCalculator.cpp
64 lines (62 loc) · 1.23 KB
/
BasicCalculator.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
int crashIt;
#include <iostream>
#include <math.h>
using namespace std;
double mathh(double num, double num2, string op) {
if (op == "*") {
return num * num2;
}
if (op == "/") {
return num / num2;
}
if (op == "+") {
return num + num2;
}
if (op == "-") {
return num - num2;
}
if (op == "^") {
return pow(num, num2);
}
if (op == "sqrt1" or op == "sqrt" or op == "sq") {
return sqrt(num);
}
if (op == "sqrt2") {
return sqrt(num2);
}
if (op == "ln") {
return log(num);
}
if (op == "log2") {
return log2(num);
}
if (op == "log") {
return log10(num);
}
if (op == "rem" or op == "remainder" or op == "fmod") {
return fmod(num, num2);
}
if (op == "cbrt") {
return cbrt(num);
}
else {
crashIt = 0;
return crashIt / crashIt;
}
}
int main() {
while (true) {
double num1;
double num2;
double zzz;
string opmath;
cout << "Please enter your first number: ";
cin >> num1;
cout << "Please enter your second number: ";
cin >> num2;
cout << "Please enter your operator (+, -, *, /, ^, sq, rem, log, ln): ";
cin >> opmath;
zzz = mathh(num1, num2, opmath);
cout << "Result: " << zzz << "\n";
}
}