Solved

# C casting problem

Posted on 2003-03-15

Here is my code #include <stdio.h>

void main(){

int len=0,j=0,i=0;int dig[20];

int y=0;

char expression[20];

printf("Enter a postfix _expression");

scanf("%s",expression);

printf("How many digits are there in your _expression ? ");

scanf("%d",&len);

for(i=0;i<len;i++)

{

if(expression[i]=='+'){

dig[i-2] += dig[i-1];

}

else

if(expression[i]=='-'){

dig[i-2] -= dig[i-1];

}

else

if(expression[i]=='*'){

dig[i-2] *= dig[i-1];

}

else

if(expression[i]=='/'){

dig[i-2] /= dig[i-1];

}

else{

dig[i] = (int)expression[i];

printf("%d\n",dig[i]);}

}/*end for*/

printf("Answer = %d\n",dig[0]);

}

The out put is not in integers

C:\EJL\myC>indi

Enter a postfix _expression22+

How many digits are there in your _expression ? 3

50

50

Answer = 100

and also * it is not working .I can't figure out a reason .Please help quickly.