Calculator: Expected 5 * - + 5 to equal 10?

If 2 or more operators are entered consecutively, the operation performed should be the last operator entered (excluding the negative (-) sign.
The sequence “5 * - + 5” = should produce an output of “10”

User story 13
This challenge is frustrating due to being contrived as heck. I check on 3 calculators. Google says the answer is -25. My phone just uses the last operation and my scientific calculator just gives a syntax error. This test case is just unfair.

This is exactly what you are being asked to implement.

Yeah except from when it’s subtraction. Which is why I say it’s contrived.

It’s not a negative sign in this context. If it was “5 * + -5”, then the last operator would be “+” and it would be “plus negative five”.

2 Likes

Nevermind. I just needed to add an else if statement just for that situation. Everything passed now. Thanks for the replies they nudged me in the right direction.

Congratulations on working through a tough problem! Happy coding.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.