If I copy and paste the above math problem to a calculator it gives out the answer as 4. I want to do the same thing in Thunkable. The numbers can be multi digits and the operators occurrence is random. I sat on this problem for couple of hour pondering … I can conceive the solution but it is too big and convoluted. Please check my starter program which can successfully do "123 + 234 + " kind of string. It will just add 123 +234 and spit out the answer as 357 going beyond that is my hurdle. Is there a easy solution or the big bulky convoluted solution I am thinking off is the only way out? Thanks
The answer should be 5. What calculator is giving you 4 as the answer?
Given 1 - 2 + 3 * 4 / 2, you multiply 3 * 4 / 2 and get 6 (either 12 ÷ 2 or 3 * 2). So 1 minus 2 is -1 and then adding 6 (from earlier) gives you 5.
If you’re trying to make a calculator app (and I would wonder why…), no there’s no easy solution. It’s going to take a lot of work to get it right.
Ok that is what I thought but thanks for confirming it. Now I can skip this feature without guilt This is something like a calculator but with limited features for a different purpose. So I will just skip this feature. Just to complete my reply I used the standard calculator which comes with Windows 11.
There they do the calculations from left to right. 1-2 = -1, -1 + 3 = 2, 2*4 = 8 and finally 8/2 = 4. You can see the last operation up there above 4. Thanks again
You’re welcome. If that’s true, then the Windows calculator isn’t following order or operations. That would really surprise me so I’m guessing you’re entering the problem from left to right and that actually, you are ignoring order of operations.
If you do need to program a calculator, there are many examples available if you Google calculator Thunkable.
Actually there are two types of order processing in calculators, the accounting type which is FCFS (First Come First Serve) or the scientific type which is BODMAS. @tatiang is referring to the more common in schools which is BODMAS. Whereas the Windows one is set as accounting type.
Thanks, I wasn’t aware of the difference.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.