PPPPPPPLLLLLLLZZZZZZZZZZZ tell me which type of logical error does exist in this program.it evaluate numerical expression correctly but the problem is in alphabetic expressions
plz tell me the output of a+b & also of a+b*c/d^e
so I'll match my output result with Ur answer
Ur replies are not satisfying me its very urgent plz give the simple answer don't confuse me or i should use any other forum ppppppppllllllllllzzzzzzzz reply as soon as possible thankyou

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<math.h>
#define MAX 20
char stack[MAX];
int top=-1;
char pop();
void push(char val);


int prcd(char symbol)
{
switch(symbol)
{
case '+':
case '-':
return 2;
case '*':
case '/':
return 4;
case '^':
case '$':
return 6;
case '(':
case ')':
case '#':
return 1;
}
}


int isoperator(char symbol)
{
switch(symbol)
{
case '+':
case '-':
case '*':
case '/':
case '^':
case '$':
case '(':
case ')':
return 1;
default:
return 0;
}
}

void convertip(char infix[],char postfix[])
{
int i,j=0;
char symbol;
stack[++top]='#';

for(i=0;i<strlen(infix);i++)
{
symbol=infix;
if(isoperator(symbol)==0)
{
postfix[j]=symbol;
j++;
}
else
{
if(symbol=='(')
push(symbol);
else if(symbol==')')
{
while(stack[top]!='(')
{
postfix[j]=pop();
j++;
}
pop();
}
else
{
if(prcd(symbol)>prcd(stack[top]))
push(symbol);
else
{
while(prcd(symbol)<=prcd(stack[top]))
{
postfix[j]=pop();
j++;
}
push(symbol);
}//end of else
} //end of else
}//end of else
}//end of for
while(stack[top]!='#')
{
postfix[j]=pop();
j++;
}
postfix[j]='\0'; //null terminate string
}//end of function

void main()
{
char infix[20],postfix[20];
clrscr();
cout<<endl<<"Enter the valid infix string:";
gets(infix);
convertip(infix,postfix);
cout<<endl<<"The corresponding postfix string is:";
puts(postfix);
int i=0;
char a,b,c;
while(postfix!='\0')
{
if(isdigit(postfix)||isalpha(postfix))
push(postfix-48);
else if(postfix!=32)
{
a=pop();
b=pop();
if(postfix=='*')
c=b*a;
else if(postfix=='/')
c=b/a;
else if(postfix=='+')
c=b+a;
else if(postfix=='^')
c=pow(b,a);
else
c=b-a;
push(c);
}
i++;
}
cout<<endl<<c;

getch();
}

void push(char val)
{
stack[++top]=val;
}
char pop()
{
return stack[top--];
}

jonsca commented: Stop flooding the forum with your question -1
nbaztec commented: Pounding 'P','L' & 'Z' keys won't fetch help. Wrapping code in code tags, will. Good luck. +0

Ques. a+b*c/d^e

Ans1. abcde^/*+
Ans2. abc*de^/+


hav fun....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.