Does anyone know how to do this?
For Example,
Problem:String = "5 + 3 * ( 10 / 2 ) + 5 * ( 10 / ( 2 + 3 ) )"
Answer:Float = GetAnswer( Problem )
Is there a easier way of doing this then having to parse through it all day?
Thanks.
Unfort. there's no "eval" function in Blitz.
You may convert it to a script or sourcecode and use a certain tool, exe, dll, interpreter to calculate it.
Personally, as long as it's only +-/* then I'd write a little function myself, to keep the app simple. Maybe there's already something in the code archives. A script interpreter thing.
what you need is a small stack based virtual machine, with an interpreter or compiler. i would show an example but no time. should be something in the code archives.
As the Moon get further away from the earth, the days get longer. Was only 20hrs long in Jurasic era
No other Idea on calc problem than those given, cept, (And I cannot do this, or know if its doable), pass it as a parameter to the calculator
The way I once did it was to count the brackets () and start with the lowest pair ie where you have ( followed by ), then work up from there. When you encounter some other symbol you do math on the numbers to each side, etc.
Alternatively in BlitzMax you could use function pointers and call functions for each kind of operation/scenario.
After a long time in front of my computer I came up with a function that will calculate a string of arithmetic. Currently it only supports "()+-*/". If you want to try it out get it from here
http://blitzbasic.com/codearcs/codearcs.php?code=1755