
-----------------------------------
killa_kid
Tue Feb 03, 2004 6:08 pm

Evaluate
-----------------------------------
I am working on a graphing program and I would like for the users to be able to input a function of their own (eg: x^3, x+3, (x^4) +3 ). I was wondering if turing had a command that would evalutate a string as a command like in javascript.

If I wanted the function x^2, i would make a string with:
currX**2

Now is there any way to get turing to execute that as is?

-----------------------------------
Cervantes
Tue Feb 03, 2004 6:14 pm


-----------------------------------
not as far as I know.  to do that involves a lot of error proofing...  I would suggest just getting the user to change the code where the equation is.

also, though x^2 is good for MSN and text on computers, in Turing its x**2

-----------------------------------
killa_kid
Tue Feb 03, 2004 6:18 pm


-----------------------------------
Uh, the x^2 is for input since that is how any computer program & calculators takes input of exponents, and in the string you see i do use ** so it would just get execed

-----------------------------------
Cervantes
Tue Feb 03, 2004 6:55 pm


-----------------------------------
well if you can trust your user to input things correctly then use the strint  command or the strreal to convert the string into an integer or real numer, respectively.  but they would have to input ** for exponents, not ^

-----------------------------------
killa_kid
Tue Feb 03, 2004 6:56 pm


-----------------------------------
the strint will parse the string and give me a value?

-----------------------------------
Cervantes
Tue Feb 03, 2004 7:09 pm


-----------------------------------
you should look at the help file, but anyways,

strint turns a string into an integer.  It won't parse it.  you have to error proof it before to make sure that the user inputs something that will correctly translate into a number.  like entering a 'q' is a nono.

also entering ("x=74*/2") is a nono :?

-----------------------------------
killa_kid
Tue Feb 03, 2004 7:11 pm


-----------------------------------
i have read the help file

but based on what u said u made it sound like it would parse

-----------------------------------
Cervantes
Tue Feb 03, 2004 7:26 pm


-----------------------------------
well if you can trust your user to input things correctly 

have you played around with it?  try different things.

it should give you a number as a result, but if the user puts in a q it'll mess up.

-----------------------------------
killa_kid
Tue Feb 03, 2004 7:31 pm


-----------------------------------
i amde a string with:

"3**2"

then did strreal and i got an error

-----------------------------------
santabruzer
Tue Feb 03, 2004 7:31 pm


-----------------------------------
because ** is a character

-----------------------------------
killa_kid
Tue Feb 03, 2004 7:40 pm


-----------------------------------
yes i know, but once again from what i am reading here i was being told i could do something along those lines

-----------------------------------
Cervantes
Tue Feb 03, 2004 7:47 pm


-----------------------------------
you can't. which is what I said at the very start.  you can do a simple version of what you are trying to do, it'll work if you input 5.  but no +, -, /, *, or **.  

I would recommend just letting the user into the code to type in the equation there.

-----------------------------------
AsianSensation
Tue Feb 03, 2004 10:07 pm


-----------------------------------
i amde a string with:

"3**2"

then did strreal and i got an error

streal does not allow conversion of ASCII values different then the arabic numbers, scientific notation, and a + or - sign (I think). To do what you wanted to do, you probably have to index for the operation sign, and then separately strint the numbers and then do the operation on them.

-----------------------------------
killa_kid
Wed Feb 04, 2004 7:15 am


-----------------------------------
believe me i've been trying  and it is really freakin hard

-----------------------------------
Cervantes
Wed Feb 04, 2004 4:28 pm


-----------------------------------
the last inclass project in gr 10 for me was this graphing assignment and my teacher told us not to worry about that part.  just let them type inside the code!

-----------------------------------
killa_kid
Wed Feb 04, 2004 6:08 pm


-----------------------------------
the point is that i dont want some idiot grade 9 (if they even use it) to mess with my code


believe me there are only like 6 or 7 good comp sci students in each grade

-----------------------------------
apomb
Wed Feb 04, 2004 8:58 pm


-----------------------------------
Instead of letting them enter the code, just put something like

[code]
put "enter variable"
get (variable)
put (variable ** 2)
[/code]

-----------------------------------
santabruzer
Wed Feb 04, 2004 9:04 pm


-----------------------------------
dude... read the rest of the thread :roll: ... anyways.. i'll get a program on it sometime.. i'm pretty close.. so far i got the idea of creating an array for the values and then adding/multiplying the odd values...

-----------------------------------
santabruzer
Wed Feb 04, 2004 9:16 pm


-----------------------------------
meh.. a stab at it, though i know there are better ways:
var str : array 1 .. 3 of string
for i : 1 .. 3
    get str (i)
end for
if str (2) = "*" and strintok (str (1)) and strintok (str (3)) then
    put strint (str (1)) * strint (str (3))
end if



-----------------------------------
AsianSensation
Wed Feb 04, 2004 11:16 pm


-----------------------------------
the point is that i dont want some idiot grade 9 (if they even use it) to mess with my code


believe me there are only like 6 or 7 good comp sci students in each grade

you can always PM someone that you think could handle the proble, and then they could fix your errors. Actually, PM me, I could probably help you out, but right now, all I'm seeing is bunch of if statements to handle the operators.
