9

I want to write a program that calculates a given math function (by the user) with specific set of values.

The user is asked to type a function, say he typed f(x)= (x^2)+3x+1 then through the program I should show the outputs of [ f(3), f(6) and f(9) ] .

The question specifically is how to fetch these x's in the typed function, then how to convert the function from a string to a double or float.

Do you have any thoughts about that ?

suppose that I'm using C , or C++

Fahd
  • 353
  • 6
  • 17
  • Possible duplicate of http://stackoverflow.com/questions/1151127/evaluating-mathematical-expressions and http://stackoverflow.com/questions/5115872/what-is-the-best-way-to-evaluate-mathematical-expression-in-c – lhf Aug 08 '11 at 01:04

1 Answers1

2

This is not an easy task, especially as operators hold precedence over others.

Have a look at some of these links so see what you're dealing with:

Equation (expression) parser with precedence?

http://en.wikipedia.org/wiki/Operator-precedence_parser

Community
  • 1
  • 1
Griffin
  • 13,184
  • 4
  • 29
  • 43
  • loool, I just realized how hard the task. I really feel like a stupid teenager :D . thx dude. – Fahd Aug 08 '11 at 00:52
  • Not a bad long-term project, though, if you're willing to put some sort of commitment to it. – kibibyte Aug 08 '11 at 00:55