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

Username:   Password: 
 RegisterRegister   
 proc only to except 4 answers otherwise loop
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
n00b.skillz




PostPosted: Sat Jan 13, 2007 6:10 pm   Post subject: proc only to except 4 answers otherwise loop

okay well i am doing a trivia game and i am wondering is there a piece of code i can stick into my procedure to make it only accept a,b,c or d instead of accepting any letter of the alphabet saying it's wrong and going on. Sort of like if the user puts "a" then it will accept and say right or wrong but if the user puts something other than a,b,c or d .... something like "k" then the program will not accept this and stay at the question until it is responded to with one of the options a,b,c or d
Sponsor
Sponsor
Sponsor
sponsor
neufelni




PostPosted: Sat Jan 13, 2007 6:42 pm   Post subject: RE:proc only to except 4 answers otherwise loop

All you need is a simple if statement.
pseudo:
if letter = a, b, c, or d then
    put "Question is right" .. or "Question is wrong"
else
    put "Invalid input"
end if
n00b.skillz




PostPosted: Sat Jan 13, 2007 7:18 pm   Post subject: Re: proc only to except 4 answers otherwise loop

yea i realize u can do it that way but can u do it without a put statement... just so the program doesn't move or just stays there until a valid choice is picked
AK.E




PostPosted: Sat Jan 13, 2007 7:31 pm   Post subject: Re: proc only to except 4 answers otherwise loop

Why not try something like this

Turing:
var letter : array char of boolean

loop
    Input.KeyDown (letter)

    if letter ('a') or letter ('b') or letter ('c') or letter ('d') then
        put "Answer is right"
        exit
    end if
end loop


Obviously that can be expanded a lot but it gives you the general idea.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: