-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.cpp
41 lines (38 loc) · 1004 Bytes
/
Calculator.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
#include <iostream>
#include <cmath>
// Varibles
double Input1, Input2, Mix;
char Action;
bool isValid = true;
// Functions
double Calculate(double _Input1, char _Action, double _Input2)
{
switch(Action)
{
case '+':{ return(Input1 + Input2); break; }
case '-':{ return(Input1 - Input2); break; }
case '*':{ return(Input1 * Input2); break; }
case '.':{ return(Input1 * Input2); break; }
case '/':{ return(Input1 / Input2); break; }
case '^':{ return(pow(Input1, Input2)); break; }
default:{ std::cout << "Unidentified Action { " << Action << " }" << std::endl; isValid = false; break; }
break;
}
}
int main()
{
std::cout << "Calculator" << " V0.1\n";
while(true)
{
isValid = true;
std::cout << "Action : ";
std::cin >> Input1 >> Action >> Input2;
Mix = Calculate(Input1, Action, Input2);
if(isValid)
{
std::cout << "Result : " << Input1 << Action << Input2 << "=" << Mix << std::endl;
}
std::cout << "------------ Restarting ------------\n";
}
return 0;
}