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<iostream.h>
#include <conio.h>
#include<string.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) ;
m=Evaluate();
cout<<m;
getch() ;
}
int Evaluate(void)
{
int i,l,a,b,q,z;
l=strlen(postfix);
for(i=0;i<l;i++)
{
if (postfix[i] != '^' &&postfix[i] != '*' &&postfix[i] != '+' &&postfix[i] != '/' &&postfix[i] != '-' )
{
push(postfix[i]);
}
else if(postfix[i] == '^' ||postfix[i] == '*' ||postfix[i] == '+' ||postfix[i] == '/' ||postfix[i] == '-' )
{
a = pop ( );
b = pop ( );
a-=48;
b-=48;
switch(postfix[i])
{
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)
{
top++;
stack[top]=item;
}
char pop()
{
char a;
a=stack[top];
top--;
return a;
}