
-----------------------------------
nelson
Thu Dec 04, 2003 9:44 pm

equation calculator
-----------------------------------
ok ,,

azn sensation called me a cheater  :o  for asking for codes,

so now i ask nicely if anyone can help me

i need to know how to do this:

user inputs an equation and i need the equation ready for 

calculations, so i can get answers by inputing x-values in to the equaition

the program should be able to handle brackets and proper bedmas


example of equation:

y = ((x+3)**2 )**(x+4)+ (x+3x*4x+5x))/3


how would i do this!!??  i'm a newbe.... so plz be detailed ^^

-nel-

-----------------------------------
Dan
Thu Dec 04, 2003 10:01 pm


-----------------------------------
well yout going to have to use a loop, substrings and some testing staments to reaed eacech chartier in the input and test to see what it is and what to do.

some things you will have to do:


test, keep track of brackets and the value in them

test for math oprations and what to do for each one (*,+,-,/,**,ect)

use BEDMAS rules you will have to keep track of number befor and after the operation and may be more depending on brackets

chack for x or any other letter and sub in the inputed value.


this will not be that easy to do right, but there are other equatin and math slolving porgames sumited in the turing section witch can help you out.

-----------------------------------
Andy
Thu Dec 04, 2003 10:01 pm


-----------------------------------
oo man... i'm not gonna give you the whole code cuz i'm lazy, but i'll give you the basic concept. you get the equation from the user as a string, then get values for x, now using index, replace all the x with the number, and use strint and such to solve

-----------------------------------
Dan
Thu Dec 04, 2003 10:06 pm


-----------------------------------
...use strint and such to solve

oh you going to do it the cheep way, lol. i like that...

-----------------------------------
Andy
Thu Dec 04, 2003 10:08 pm


-----------------------------------
how else would u do it? if ur not gonna strint the numbers and have if statements for the operators?

-----------------------------------
Dan
Thu Dec 04, 2003 10:12 pm


-----------------------------------
oOo, nvm i thougth you ment somting eltes. i forgot turing dose not do that (as in if you have string "1+1" it whould go to 2). i have been doing to many languges lattey all geting mixed together. sory about that mixup. (seems like i am making to many today)

-----------------------------------
nelson
Thu Dec 04, 2003 10:15 pm

hmm
-----------------------------------
what do you mean by "using index"

and is that a dark templar?

-----------------------------------
Andy
Thu Dec 04, 2003 10:20 pm


-----------------------------------
index is a function that returns the first occurence of a substring inside a string. type that on turing and press F9, and yes that is a dark templar as you can see from the cape

-----------------------------------
nelson
Thu Dec 04, 2003 10:28 pm

d
-----------------------------------
ok i know how to keep track of things , numbers, +-*/ using strint 

and stuff 

but i woudn't know how to program where in the equation the calculation 

should start 



cool 
my id is nelsonmuntx in battlenet, if you still play and interested 


and HA ! it doesn't say i'm newbe anymore,, TAKE THAT TONY!@!

-----------------------------------
Tony
Thu Dec 04, 2003 11:33 pm


-----------------------------------
pff :roll:

thats exactly what I told you to do Brian, but NOO...

let me try it again... you start from outside the brackets (if it makes it any easier, put the entire function into another set of brackets to start everything off) and consentrate just on whats inside of those brackets.

if there're another set of brackets inside there, you take just that set and solve that first.

You basically move in, then move out. You'd have to use a self-calling function that accepts a string with part/whole function to break it appart into pieces.

Maybe you'll listen to me now that this is writen down on a forum :lol:
