have the user enter the expression in postfix
Code:
char array[MAX];
char ch;
int i=0;
while (ch=(char) getc(stdin)){
array[i]=ch;
}
int pop(int a)
{
return array[a];
}
void push(int b)
{
array[countvar]=b;
}
the basic idea is this: if the element is a number, pop it from the stack. If it is an operand, then add/sub/mult/divide the two numbers popped from the stack and push the result.
Here is an example: 67+12++ (this is 6+7+1+2)
the program pops 6 and 7, sees the +, adds 6+7, and pushes 13 so the resulting expr is 1312++, which evaluates to 133+, which evaluates to 16.
In reality it is harder, because you will have to deal with conversions. Also, it is nice if you incorporate the whole thing into a struct or class, and make pop and push private functions. That way it is easier to have a countvar that keeps track of where you are in the stack.