Computer Science Canada If Help! |
Author: | mike200015 [ Sat Mar 12, 2005 11:01 pm ] | ||
Post subject: | If Help! | ||
In my game i have :
and answer is an int, and if the user enters something other than an int, it messes up the program, and gives me an error, since its the wrong type, so i want to make it error proof, and keep asking the question, and then if what the user types in is any int, then it will continue the game. So how would i make the program check if the input is any int ![]() |
Author: | Bacchus [ Sat Mar 12, 2005 11:42 pm ] |
Post subject: | |
strintok() strint() F10 there may also be a tutorial on error proofing |
Author: | mike200015 [ Sat Mar 12, 2005 11:44 pm ] |
Post subject: | |
im not trying to switch from a string to an int or anything.. i jus want to chek if the input was any int number.. and if it was.. then continue on |
Author: | Bacchus [ Sat Mar 12, 2005 11:49 pm ] | ||
Post subject: | |||
|
Author: | mike200015 [ Sat Mar 12, 2005 11:59 pm ] |
Post subject: | |
ooo.. ok i get it now.. yea it works great.. thanx! ![]() |
Author: | mike200015 [ Sun Mar 13, 2005 12:03 am ] |
Post subject: | |
Another thing i want to error proof is.. i ask the user to enter their name.. and i want to make it loop the question if they enter more than 15 characters.. so how would i make a loop for that.. and it exits when the user inputs 15 characters or less? |
Author: | Flikerator [ Sun Mar 13, 2005 12:12 am ] | ||
Post subject: | |||
mike200015 wrote: Another thing i want to error proof is.. i ask the user to enter their name.. and i want to make it loop the question if they enter more than 15 characters.. so how would i make a loop for that.. and it exits when the user inputs 15 characters or less?
|
Author: | mike200015 [ Sun Mar 13, 2005 12:35 am ] |
Post subject: | |
hey .. thnx Flickerator.. worked great! ![]() |
Author: | Cervantes [ Sun Mar 13, 2005 9:04 am ] |
Post subject: | |
Flik: you don't need that exit when name = name part. Simply typing exit is good enough. Also, it would be a good idea to use get : *. Try running flik's code, and inputing "ABCDEFG HIJKLMNO". That string is >= 16, but it tells you you're name is ABCDEFG because get stops at spaces. get : * only stops at enter, however, so it will take the whole line of input into the variable. Also, if you don't have get : *, it can mess up the next get in your program. Without the : *, try inputting "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA". All the A's before the space will be put into the name variable. Name is greater than 16, so it tells you that it is and restarts the loop. Then it trys to get input again, but there's still stuff in the keyboard buffer. So it takes that stuff, and then puts it into name. name is once again greater than 16, so it tells you so, AGAIN! Cheers, -Cervantes |
Author: | Flikerator [ Sun Mar 13, 2005 11:26 am ] |
Post subject: | |
Cervantes wrote: Flik: you don't need that exit when name = name part. Simply typing exit is good enough.
Also, it would be a good idea to use get : *. Try running flik's code, and inputing "ABCDEFG HIJKLMNO". That string is >= 16, but it tells you you're name is ABCDEFG because get stops at spaces. get : * only stops at enter, however, so it will take the whole line of input into the variable. Also, if you don't have get : *, it can mess up the next get in your program. Without the : *, try inputting "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA". All the A's before the space will be put into the name variable. Name is greater than 16, so it tells you that it is and restarts the loop. Then it trys to get input again, but there's still stuff in the keyboard buffer. So it takes that stuff, and then puts it into name. name is once again greater than 16, so it tells you so, AGAIN! Cheers, -Cervantes Wow I didn't know about thatr keyboard buffer part, good to know. I also didn't know about just exit so thanks ^^; |
Author: | mike200015 [ Mon Mar 14, 2005 3:00 pm ] |
Post subject: | |
yea i used the :* after the get.. helps also wit the error proofing. Thanx ![]() |