how to give equation to a program

How can i give an equation to calculate?

For example:

cin>> equation;
//equation is y = 5*(x/2);

then:
cin>>x;
//x is 6;

then:
// y = 5 * ( 6 / 2 ) = 15;
cout<< y;
//y is 15;

the equation needs to be entered from input by the user.

I'm using visual studio 2010 c++ console application.


Last edited on
1
2
3
4
5
6
7
cout << "Enter x: ";
int x;
cin >> x;

double y = 5*(x/2.0);

cout << "y = " << y << endl;
thank you rehan,

But the equation needs to be entered from input by the user.
You'll probably need to use some kind of interpreter of the string. I've never heard of a built-in equation system.
Yes Bourgond thank you,
I'll do that. i thought there might be some other ways.
@mrm40: Do post your code here when done, I'm curious to see it.
Last edited on
@reham:
till i complete my code you can see the algorithm I'm going to follow,

http://en.wikipedia.org/wiki/Shunting_yard_algorithm

@bourgond: what is your idea?
Topic archived. No new replies allowed.