-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculatorv4.cpp
More file actions
73 lines (62 loc) · 1.49 KB
/
Copy pathcalculatorv4.cpp
File metadata and controls
73 lines (62 loc) · 1.49 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <cmath>
int main(){
double n0 = 0, n1 = 0, o0 = 0;
std::string restart0 = "y";
std::string c0 = "E";
while(restart0 == "y")
{
std::cout << "CalculatorV4-Input the first number!" << '\n';
std::cin >> n0;
std::cin.clear();
fflush(stdin);
std::cout << "what function do wou want to perform? + - * / ^ sqrt" << '\n';
std::cin >> c0;
if (c0 == "sqrt")
{
goto skip;
}
std::cout << "Input the second number" << std::endl;
std::cin >> n1;
std::cin.clear();
fflush(stdin);
skip:
if (c0 == "+")
{
o0 = n0 + n1;
std::cout << "the answer is " << o0 << '\n';
}
else if (c0 == "-")
{
o0 = n0 - n1;
std::cout << "the answer is " << o0 << '\n';
}
else if (c0 == "*")
{
o0 = n0 * n1;
std::cout << "the answer is " << o0 << '\n';
}
else if (c0 == "/")
{
o0 = n0 / n1;
std::cout << "the answer is " << o0 << '\n';
}
else if (c0 == "^")
{
o0 = pow(n0, n1);
std::cout << "the answer is " << o0 << '\n';
}
else if (c0 == "sqrt")
{
o0 = sqrt(n0);
std::cout << "the answer is " << o0 << '\n';
}
else
{
std::cout << "ERROR" << '\n';
}
std::cout << "Restart? y/n" << '\n';
std::cin >> restart0;
}
return 0;
}