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

Username:   Password: 
 RegisterRegister   
 Avoiding Crashes
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
noob




PostPosted: Sun Mar 16, 2003 8:45 am   Post subject: Avoiding Crashes

I'm trying to avoid crashes due to bad data input, but I don't seem to know how to do it. I want to get the name of a person, and check the length of the name. For ex. I want the name to be less than 25 characters long, but in turing if someone enters one more than 25 letters, there's an error leading back to the code, I want to know how to output the error onto the run window saying its too long and have them re-input the name.

Thanks for the help in advance.
Sponsor
Sponsor
Sponsor
sponsor
azndragon




PostPosted: Sun Mar 16, 2003 9:39 am   Post subject: (No subject)

This should help.

code:
var name : string
var length_of_name : int

loop
put "Enter your name"
get name
length_of_name := length (name)
exit when length_of_name <=25
end loop


This makes it so that it keeps on asking their name, until it's less than or equal to 25 characters. When that happens, it exits the loop, and will do whatever comes after it. Hope this helps.

Edit: Dan - gave some bits to him for helping
noob




PostPosted: Sun Mar 16, 2003 10:43 am   Post subject: (No subject)

Thanks a lot
jamez




PostPosted: Sun Mar 16, 2003 11:29 am   Post subject: (No subject)

or just
code:

var name:string

loop
    get name:*
    exit when length(name) <=25
    cls
end loop


Didn't need that xtra var Very Happy


Edit: Dan - gave bits for helping
azndragon




PostPosted: Sun Mar 16, 2003 11:47 am   Post subject: (No subject)

Yeah, that's actually better, but I like using tons of variables for some reason. Keeps the program more organized.
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  [ 5 Posts ]
Jump to:   


Style:  
Search: