> when I put in an expression e.g., "3+4-6", I keep getting either 51 or 52.
let me see if I understand, you write
3+4-6
as input, and sometimes you've got 51 as output, but other times you've got 52, when it is obvious that you should get 54.
opStack.pushOp(exp.find_first_of("+-*/"));
¿what are you trying to do here?
valStack.pushVal(exp[i]);
, you are not pushing
3
, but
'3'
, whose ASCII code is 51.
1 2 3
|
int x = valStack.popVal();
int y = valStack.popVal();
char op = opStack.popOp();
|
that looks like the algorithm to evaluate a
postfix expresion.
> I changed up a bit of my code from the last post I made of this assignment
please don't create new threads, just reply to the old one. That way we can have the history, like knowing what the assignment is about.