Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Evaluate
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
killa_kid




PostPosted: Tue Feb 03, 2004 6:08 pm   Post subject: 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:
code:
currX**2


Now is there any way to get turing to execute that as is?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Feb 03, 2004 6:14 pm   Post subject: (No subject)

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




PostPosted: Tue Feb 03, 2004 6:18 pm   Post subject: (No subject)

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




PostPosted: Tue Feb 03, 2004 6:55 pm   Post subject: (No subject)

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




PostPosted: Tue Feb 03, 2004 6:56 pm   Post subject: (No subject)

the strint will parse the string and give me a value?
Cervantes




PostPosted: Tue Feb 03, 2004 7:09 pm   Post subject: (No subject)

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 Confused
killa_kid




PostPosted: Tue Feb 03, 2004 7:11 pm   Post subject: (No subject)

i have read the help file

but based on what u said u made it sound like it would parse
Cervantes




PostPosted: Tue Feb 03, 2004 7:26 pm   Post subject: (No subject)

Cervantes wrote:
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.
Sponsor
Sponsor
Sponsor
sponsor
killa_kid




PostPosted: Tue Feb 03, 2004 7:31 pm   Post subject: (No subject)

i amde a string with:

"3**2"

then did strreal and i got an error
santabruzer




PostPosted: Tue Feb 03, 2004 7:31 pm   Post subject: (No subject)

because ** is a character
killa_kid




PostPosted: Tue Feb 03, 2004 7:40 pm   Post subject: (No subject)

yes i know, but once again from what i am reading here i was being told i could do something along those lines
Cervantes




PostPosted: Tue Feb 03, 2004 7:47 pm   Post subject: (No subject)

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




PostPosted: Tue Feb 03, 2004 10:07 pm   Post subject: (No subject)

killa_kid wrote:
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




PostPosted: Wed Feb 04, 2004 7:15 am   Post subject: (No subject)

believe me i've been trying and it is really freakin hard
Cervantes




PostPosted: Wed Feb 04, 2004 4:28 pm   Post subject: (No subject)

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!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: