blob: b65b44d541cb6996a6db04566ee5c595df7360dd (
plain) (
tree)
|
|
#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)) != EOF) {
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;
}
|