aboutsummaryrefslogtreecommitdiff
path: root/7.5/main.c
diff options
context:
space:
mode:
Diffstat (limited to '7.5/main.c')
-rw-r--r--7.5/main.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/7.5/main.c b/7.5/main.c
new file mode 100644
index 0000000..cf5194e
--- /dev/null
+++ b/7.5/main.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "stk.h"
+#include "op.h"
+
+#define MAXOP 100
+
+int main(void)
+{
+ char op[MAXOP];
+ int opd2;
+ int c;
+
+ while ((c = getop(op, MAXOP))) {
+ switch (c) {
+ case NUM:
+ push(atof(op));
+ break;
+ case '+':
+ push(pop() + pop());
+ break;
+ case '-':
+ opd2 = pop();
+ push(pop() + opd2);
+ break;
+ case '*':
+ push(pop() * pop());
+ break;
+ case '/':
+ opd2 = pop();
+ push(pop() / opd2);
+ break;
+ case '\n':
+ printf("\tans: %.2lf\n", pop());
+ clear();
+ break;
+ default:
+ printf("err: unkown operator: %c\n", c);
+ break;
+ }
+ }
+
+ return 0;
+}