what's wrong with this infix to postfix conversion

#include <iostream>
#include <string>
#include <stdlib>

class IntoPost{
private:

char post[100];
char stackArr[100];
int top;
int num;

public:

char infix[100];

stack(){
num=0;
top= -1;
}

void push(char op){
stackArr[++top]=op;
}

char pop(){
return(stackArr[top--]);
}

bool isEmpty(){
return(top==-1);
}

void gotPost(char op){
post[num++]=op;
}

void gotOper(char op, int pre1){

while(!isEmpty()){
int pre2;
char opTop=pop();

if(opTop=='+'||opTop=='-'){
pre2=1;
}
else{
pre2=2;
}

if(pre2<pre1){
push(opTop);
}
else{
gotPost(opTop);
}
}
push(op);
}

void showPost(){
while(!isEmpty()){
post[num++]=pop();
}

cout<<post;
}
};
int main(){
IntoPost Ip;

cout<<"Enter infix expression: ";
cin.getline(Ip.infix, 100);

for(int i=0;i<strlen(Ip.infix); i++){
char sign=Ip.infix[i];

switch(sign){
case'+':
case'-':
Ip.gotOper(sign, 1);
break;
case'*':
case'/':
Ip.gotOper(sign, 2);
break;
default:
Ip.gotPost(sign);
break;
}
}


Ip.showPost();

cin.get();
cin.get();

return 0;
How about you step through it with a debugger and let us know what you find?
Topic archived. No new replies allowed.