Hi,
I am working on a calculator with postfix notation. I have copy/pasted a small section of the main program below. Even though I declare variables such as E, L, or pow in a typedef statement, my unix compiler does not recognize these variables as defined. Please help.
Code:/* Code begins */ typedef enum { PLUS='+', MINUS='-', MULT='*', DIV='/', POW='pow', LOG='L', EXP='E', NUM='#', PRINT=';', NL='\n', UNKNOWN='?' } Token; Token cur_token; double number; main() { double op2, op1; char s[MAXOP]; int top = 0; while ((cur_token = GetToken(s)) != EOF) { switch (cur_token){ case NUMBER: push(atof(s)); break; case PLUS: push(pop()+ pop()); break; case MULT: push(pop()* pop()); break; case MINUS: op2 = pop(); push(pop() - op2); break; case DIV: op2 = pop(); if (op2 != 0.0) push(pop()/op2); else printf("error: zero divisor\n"); break; case EXP: push(E(pop())); break; case POW: op2 =pop(); op1 =pop(); push(pow(op1, op2)); break; case LOG: push(L(pop())); break; case NL: printf("\t%.8g\n", pop()); break; case PRINT: printf("\t%.8g", stack[top-1]); break; default: printf("error: unknown command %s\n", s); break; } } /*end of while statement*/ return 0; } /* Code ends */
[code][/code]tagged by Salem



LinkBack URL
About LinkBacks


