Equations Input

How do I ask a user to input an equation and have the code then use their equation and give an answer.

Example: User inputs x^2 + x - 2
I want the program to store that in memory and when the user gives an x value, it uses that equation that the user inputted and gives out a number.

x input 1 = y output 0
x input 2 = y output 4
etc....
You can pass an equation in as a simple string but you're going to need to do a LOT of work parsing the string and performing the calculation. Unlike other high level languages C++ has no Eval() function [cnoeval = C, no eval() - Ha!] so you can't just give it an equation to evaluate, you have to do all the grunt work yourself. I'm sure you can find a library to help with that part though. Stroustrups' Programming - Principles and Practices has a good implementation of how to do it with pure C++.
What I am trying to do is build program that uses the secant method but I don't have any other way of getting around it. I don't know how to tackle the problem. I was only told to make a program that uses the secant method and that is all. Can you help me with that?
The secant method is an algorithm that uses an iterative approximation approach to finding the root of a function. http://en.wikipedia.org/wiki/Secant_method Check out the animation page linked at the bottom to get a good overview of the process.

Try Googling "secant method C++" and you'll find some examples of code that might get you started.
Topic archived. No new replies allowed.