maha khaled 0 Newbie Poster

Hi, i'am try to read postfix expression from txt file and evaluate it
the input is "10 5 *" ,the output should be 50, but it shows -43 , where's the error ?
here's my code
#include <iostream>
#include <iomanip>
#include <fstream>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
using namespace std;
#define SIZE 40
int stack[SIZE];
int top=-1;

void push(int n)
{
if(top==SIZE-1)
{
printf("Stack is full\n");
return;
}
else
{
top=top+1;
stack[top]=n;
printf("Pushed element is %d\n",n);
}
}

int pop()
{
int n;
if(top==-1)
{
printf("Stack is empty\n");
return 0;
}
else
{
n=stack[top];
top=top-1;

return(n);
}
}

int main()
{

int str[50],ch;

int i=0;
int n,op1,op2;

ifstream inFile;
ch=str[i];

inFile.open("D:\me.txt");
if (!inFile)
{
printf( "Unable to open file");
system("pause");
exit(1); // terminate with error
}

while (inFile >> ch)
{
if(ch==43 || ch==45 || ch==47 || ch==42 || ch==94 || ch==37 )
{

op1=pop();
op2=pop();
if (op1<op2)
{
n=op1;
op1=op2;
op2=n;
}
if(ch==43)
n=op1+op2;
else if(ch==45)
n=op1-op2;
else if(ch==42)
n=op1*op2;
else if(ch==47)
n=op1/op2;
else if(ch==37)
n=op1%op2;
else if(ch==94)
n=op1^op2;
else
{
printf("The operator is not identified\n");
exit(0);
}
printf("n=%d\n",n);
push(n);

}
else
{
n=ch-'0';
push(n);
}
ch=str[++i];
}

inFile.close();
printf("The value of the arithmetic expression is=%d\n",pop());
system("pause");
return 0;
}
`