Calculator halp

Everything with my algorithm works except with multiple operators like “5*+8”. I’m splitting my input array into arrays of numbers and operators currently, and I’m not sure if there’s a way to handle multiple operators without reworking my logic from the ground up.

Any hints would be greatly appreciated :slightly_smiling_face:

The only time you really need multiple operators would be in the case of something like “5*-8”. Otherwise, your application should just use the last operator entered. For example, if the user enters “5*+8”, the “+” would replace the “*” with “+”, so it ends up being “5+8”.

On a separate note, you have a lot of repeated code that could be made DRY (Do Not Repeat Yourself) by creating some functions for the repeated code.

You are going to have to do something before just concatenating the existing cur with the new input. You need some extra logic to remove the last element of curr if it is an operator and the current input is any operator except “-”.

1 Like

Thank you for the guidance. I’m confident I can rework the code and pass now. I kept thinking I would have to rework my calculation algorithm. I also see now a couple spots where I can eliminate repeated code too.:slightly_smiling_face: