as my first project after watching the videos of McWorther I want to make a PEMDAM calculator.
So you can enter a calculation in the serial monitor and the end result is displayed on a LED screen.
So far no problem
But is it a good waty to use two stacks to take care that the calculations are done in the right order or is there a better way ?
yes. I mean that
I was thinking of 2 stacks. one for the numbers and one for the operations.
So lets say we want to solve this calculation : 2 + 3 * 8
Then I first store the 2 in the numbers stack
Then I see a + so I store it on the operations stack.
Then I see a 3 so I store it on the numbers stack
Then I see a * so I can "compare" if the * has a higher priority as the + which it has
Then I see the 8 so I can get a operation from the operations stack and a number and calculate 3 * 8 which is 24.
Then I can store the 24 in the numbers stack.
Then I can get 2 numbers from the numbers stack and a operation so I can calculate 2 + 24 = 26
Which is then the answer.
I hope this explanation is clear.