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

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




PostPosted: Sat Mar 12, 2005 11:01 pm   Post subject: If Help!

In my game i have :
code:
get answer

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 Question
Sponsor
Sponsor
Sponsor
sponsor
Bacchus




PostPosted: Sat Mar 12, 2005 11:42 pm   Post subject: (No subject)

strintok()
strint()
F10

there may also be a tutorial on error proofing
mike200015




PostPosted: Sat Mar 12, 2005 11:44 pm   Post subject: (No 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
Bacchus




PostPosted: Sat Mar 12, 2005 11:49 pm   Post subject: (No subject)

code:
var errorproof:string
var num:int
loop
   cls
   put "Please enter an Integer"
   get errorproof
   if strintok(errorproof) then
      num:=strint(errorproof)
      exit
   end if
   put "That is not an Integer!"
   delay(500)
end loop
put "That IS an Integer!"
mike200015




PostPosted: Sat Mar 12, 2005 11:59 pm   Post subject: (No subject)

ooo.. ok i get it now.. yea it works great.. thanx! Very Happy
mike200015




PostPosted: Sun Mar 13, 2005 12:03 am   Post subject: (No 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?
Flikerator




PostPosted: Sun Mar 13, 2005 12:12 am   Post subject: (No 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?


code:
var name : string
loop
    put "Enter a name (Less then or equal to 15 chars)"
    get name
    if length (name) >= 16 then
        put "I sad less then or eqaul to 15!"
        delay (500)
        cls
    else
        exit when name = name
    end if
end loop
put "Your name is ", name
mike200015




PostPosted: Sun Mar 13, 2005 12:35 am   Post subject: (No subject)

hey .. thnx Flickerator.. worked great! Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun Mar 13, 2005 9:04 am   Post subject: (No 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
Flikerator




PostPosted: Sun Mar 13, 2005 11:26 am   Post subject: (No 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 ^^;
mike200015




PostPosted: Mon Mar 14, 2005 3:00 pm   Post subject: (No subject)

yea i used the :* after the get.. helps also wit the error proofing. Thanx Smile
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  [ 11 Posts ]
Jump to:   


Style:  
Search: