Executing a string !!
How can i execute an equation passed as a string??
For ex: if i have
x=2 (integer)
"y = 2 * x + 1" (string)
how can i obtain 5 as result ???????????????????
Thanks...
Printable View
Executing a string !!
How can i execute an equation passed as a string??
For ex: if i have
x=2 (integer)
"y = 2 * x + 1" (string)
how can i obtain 5 as result ???????????????????
Thanks...
It will not execute the string. You must write the code to do the math.
You have this:
x = 2 <-- integer
"y = 2 * x + 1" <-- string
But you must also have code to solve the problem. An advanced calculator may be what you need. I used a TI-85 in high school and college. That would be easier than writing the code to extract the variables from the string and then performing the math to solve for x.
...later