-
how get an equation ?
hello .
I have to write a program that must take an equation from user and then give the answer .
for example it must take --> ( cosx+1-x=0 ) then give the answer --> 1.2786 .
I know how to reach the answer but
I dont know how to get the equation . if I put it in a string then what I must do to tell to the program that the string is a math formula and for example ---> c o s x is cos x and .....?:confused:
hope I could tell my meaning well .
tnx .
-
there are many algorithms for doing this, I remember implementing a simple scripting language a while back using one of those to parse arithmetic expressions, it's called the shunting yard algorithm, not that hard to implement, but you need to be familiar with stacks
EDIT:
check out this site:
http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm
for algorithm description and pseudo code.
-
Use a two-step format:
1) parse the equation to figure out the operators (+-*/) and operands, and put them in a buffer to calculate later. Look up an algorithm for Reverse Polish Notation.
2) process the new buffer to arrive at the answer.
-
tnx alot .
but I need more help plz .
my english isn't good and I dont undrestand the parsing algorythm explanation .
I have written a program that turns an infix sentence to postfix(suffix) form of it some months ago . but the out put is an string too . what can I do ?
tnx again for helping .
-
You'll have to explain what you have better than that. What output is a string?