-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (31 loc) · 947 Bytes
/
main.cpp
File metadata and controls
35 lines (31 loc) · 947 Bytes
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
#include <string>
#include "Calc.h"
#include "utils.h"
int main()
{
std::string welcome_msg{"Arithmetic calculator\nType \'q\' to quit"};
std::string exit_msg{"Thanks for trying out my calculator\nGoodbye!"};
printf("%s\n", &welcome_msg);
// create the calculator object.
Calc *c = new Calc();
// expr stores the string representation of the expression
std::string expr;
// continuous feedback loop
while (true)
{
printf("Enter Arithmetic Expression: ");
scanf("%s", &expr);
// exit loop if q was typed
if(exitCode(expr))
break;
// create the BET using a postfix version
// of the input prefix expression
node* exp_tree = c->expressionTree(expr);
// evaluate the BET
double n = c->evaluate(exp_tree);
// print value of expression
printf(" = %f", n);
}
printf("%s\n", &exit_msg);
return 0;
}