I'm doing an advanced calculation process (something similar to scientific mode for calculator). I'm seeking for algorithm that can help me finish this task for my project. Here is the problem:
Let take an example 10+10*2
. The result of this SHOULD be 30
. So, the problem I'm facing is that divide and multiply should take advantage of +
and -
operation (even without brackets). I basically know how to do a calculator which have basic functions like result of 10+10*2
is 40
(put first number in variable, then second in another variable, and third in first variable again). In regard, I wrote a few algo but none of them worked. My solution to this would be to parse whole strng '10+10*2'
and then split them apart to detect operations +, -, / and *. Then recalculate the process. But that seems a bit longer and I suspect a lot of "if" conditions plus who use a string while calculating?
We can discuss about any idea.
Thanks!
P.S. I'm familiar with a few languages so any solution can be made. I accept pseudo codes in various high-level languages. I'm just not familiar with algo (programming logic).