hi my problem is that
whan i want to add 2+3 i enter it in postfix 23+ it give me 5 which is correct but whan i want to add 20+30 i enter 2030+ it add me 3&0 because i use char so, this progm is limited to 1 digit.so help me so tht i can can evaluate 12,7,3,-,/,2,1,5,+,*,+ so help me solving this problem thanks

#include <stdio.h>
#include <conio.h>
#define MAX 50
char stack[MAX] ;
char postfix[MAX] ;
int top=-1;
char pop();
void push(char);
int Evaluate(void);
int power(int b,int a)
{if (a==0)
return 1;
return b*power(b,a-1);}
void main()
int m;
clrscr() ;
cout<<"enter postfix equation: ";
gets(postfix) ;
getch() ;
int Evaluate(void)
int i,l,a,b,q,z;
if (postfix[i] != '^' &&postfix[i] != '*' &&postfix[i] != '+' &&postfix[i] != '/' &&postfix[i] != '-' )
else if(postfix[i] == '^' ||postfix[i] == '*' ||postfix[i] == '+' ||postfix[i] == '/' ||postfix[i] == '-' )
a = pop ( );
b = pop ( );

 case '^' : q=power(b,a); break;
case '+' : q=b+a; break;
case '-' : q=b-a; break;
case '*' : q=b*a; break;
case '/' : q=b/a; break;
push ( q );
z = pop ();
return z;
void push(char item)
char pop()
char a;
return a;

For what type is it legal to use more than one char at a time in the type? That's the type that should be used to declare stack and the variables called a and b. Then you will need some other mechanism to convert that type to numerical values besides the -= 48 protocol. Once you have figured out the type to use, then the way to convert that type to numerical version will be easier to see, too, hopefully.

When you want to bump your own post it is best to post a request for clarification, etc, and not request assistance for your thread from a different, even if similar, thread.

I'd suggest changing stack to either be of some numerical type. If the input expression is something like this:

-0.6 37.6 + 47 * sin30 *

then you can use the >> to separate the different "tokens" in the expresion (a token can be either an operand or an operator) into strings. Evaluate the token string to see if it is an operand or an operator. If it is an operand then convert the token string to an appropriate numerical type and pop the numerical type onto a(n approriately declared) stack. If the token string is an operator then pop the appropriate number of operands from the stack, do the appropriate calculation and push the result back onto the stack. Since the tokens representing operators will also be strings you can either use an if/else sequence using strings as comparisons or use the first char of the string as the comparison in a switch statement.