postfix calculator
Mar 11, 2011 at 6:26am UTC
hey guys i'm trying to make a postfix calculator..when you read each char, it check whether it is a digit - if it is, convert it to an int...but i can't get my program to separate the operands and operators?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# include <iostream>
# include <stack>
# include <string>
using namespace std;
int main()
{
stack <int >myStack;
string postFix;
char ch,op;
int hold;
cin>>postFix;
for (int count=0; count <= postFix.length(); count++)
{
ch = postFix[count];
if ((ch<=9) && (ch>=0))
{
hold=ch-'0' ;
myStack.push(hold);
}
else
{
cout<<ch;
myStack.push(ch);
}
}
return 0;
}
Last edited on Mar 11, 2011 at 6:27am UTC
Mar 11, 2011 at 7:32am UTC
line 16: you're comparing two different types a char and literal integer, consult the ANSI table for a correct way to do your comparison
Mar 11, 2011 at 5:22pm UTC
I got it! Thanks a lot for your advice i really appreciate!
Topic archived. No new replies allowed.