0

The program should have a loop asking the user whether or not they have an infix expression to enter. If the answer is “yes”, the program should prompt the user to input the next expression.

I’ve got this down

The expression must be entered as a single string. The input string must be echoed back out as a string.

The program must use the 2-stack method to evaluate the expression. Print the numerical value.

Use this data: 3*(4+2*(6-4)+1)+2*3 2.75 * ((3 + 1.) – (_3.14159*7+3.1))
The underscore symbol _ means the number is negative.

I understand how to use the 2-stack method, I’m just having trouble coming up with a way to build up the number piece by piece. For example, _3.14159, I’m thinking I’ll need a loop to go through and update a number (int n for example) after each char is read in. I just can’t wrap my head around exactly how to do it. If someone could point me in the right direction it’d be greatly appreciated.

Edit: I haven’t found anything else that addresses this specifically. We can’t use a built in method to do this, we need to make it ourselves. Also, other examples don’t seem to account for doubles.

user3473451
  • 53
  • 2
  • 8

0 Answers0