0

Is easy to calculate a value from a math. formula in c++ if you code it

int x;
result = (x * x) + 3 / 4;

But, what if i wanna READ the function? i mean, if the user gives me a string like:

"(x * x) + 3 / 4"

i want to be able to do calculations with that formula like know the result if "x" is "1.12". I tried to make a library that reads these, but when this starts to be complicated like using "sin" or fractional numbers "3/7". Im thinking about use a program that calls Python to put that in the IDLE and read the result. Is any better way to do this?

  • 1
    Does this answer your question? [Convert string to mathematical evaluation](https://stackoverflow.com/questions/9439295/convert-string-to-mathematical-evaluation) – Juan Antonio Jun 07 '20 at 23:49
  • FYI: [The Tiny Calculator Project](https://stackoverflow.com/a/46965151/7478597) – Scheff's Cat Jun 08 '20 at 05:55

0 Answers0