proc only to except 4 answers otherwise loop
Author |
Message |
n00b.skillz
|
Posted: 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
|
|
|
neufelni
|
Posted: 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
|
Posted: 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
|
Posted: 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. |
|
|
|
|
|
|
|