take a mathmatic expression from user..

Jun 22, 2011 at 7:50am
Hi, I need a code , take from user an expression :

ex:

pow(x,(2*x+3)/pow(x+3,o.5))/log(x)+4*sin(x/5)+log10(x)+sqrt((x^2+5x)/(x+1))

...
and do the math...could someone help me please..!
Jun 22, 2011 at 10:59am
This is a far harder problem than you probably think it is.

Such a thing would require you to lexically analyse the input string, and essentially carry out some kind of compilation on the anaylsed tokens.

It'd be simpler to just use a library someone else already wrote.
Jun 22, 2011 at 3:43pm
I suggest you read Stroustrup's Programming Principles and Practices. The first several chapters are based on creating a token parsing expression evaluation program from scratch. It's pretty complex, but it teaches you a LOT of C++ along the way.

Of course I couldn't help chiming in with the username "cnoeval" (i.e.: C, no Eval). 8*)
Jun 22, 2011 at 6:14pm
This would be pretty complex, as in a lot of little pieces working together, but not TOO complicated I think.

Before getting into this though I need to ask how much C++ do you know? Specifically C++ in this case since my solution is object oriented.
Topic archived. No new replies allowed.