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

Username:   Password: 
 RegisterRegister   
 Make sure someone enters a string
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chelsee




PostPosted: Sat Dec 16, 2006 8:55 pm   Post subject: Make sure someone enters a string

How do I make sure someone enters a string instead of an int or real?
Sponsor
Sponsor
Sponsor
sponsor
Ultrahex




PostPosted: Sat Dec 16, 2006 9:03 pm   Post subject: (No subject)

easiest way is read everything in as a String and check and then convert for using strintok ( s : string ) : boolean and check whether it is then convert and set as your integer variable.
mish




PostPosted: Sat Dec 16, 2006 10:44 pm   Post subject: (No subject)

you would have to errortrap the user input. you would have to of course put declare variables first.
ericfourfour




PostPosted: Sat Dec 16, 2006 10:45 pm   Post subject: (No subject)

You should actually use strrealok. This method will return true if a string can be converted to a real number. It will return false if it cannot.
code:
var number : string
get number
put number, " is "..
if not strrealok (number) then
    put "not" ..
end if
put " a number."
mish




PostPosted: Sat Dec 16, 2006 10:47 pm   Post subject: (No subject)

LOLL whats a strrealok? o_O that looks an awful lot like an errortrap to me >.<
StealthArcher




PostPosted: Sat Dec 16, 2006 10:53 pm   Post subject: (No subject)

Specifically these statements say "String OK", or in the case you refer to"String-Real OK" meaning that the given input can work with the stated conditions.
ericfourfour




PostPosted: Sat Dec 16, 2006 11:49 pm   Post subject: (No subject)

mish wrote:
LOLL whats a strrealok? o_O that looks an awful lot like an errortrap to me >.<

F10. I think there is also a tutorial on it. And did you not read my post? I said exactly what it does.
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 1  [ 7 Posts ]
Jump to:   


Style:  
Search: