var choice:array 1..4 of string
choice[1] = "a"
choice[2] = "b"
choice[3] = "c"
choice[4] = "d"
var answerIndex:int := 2 % the answer is "b"
%// ofcourse all of the above should be loaded from a datafile
%so we have an array full of answers and we know that 2nd one is correct.. aka choice(answerIndex)
%now lets say we want to let the user pick just 2 of the above (after using 50-50)
var wrongChoices:array 1..3 of int %all the wrong answers
var myChoices:array 1..2 of int %1 correct 1 wrong
var counter:int := 1 %just follow along
for i:1..4
if i not= answerIndex then
wrongChoices(counter) := i
counter += 1
end if
end for
%now wrongChoices has all of the indexes but answerIndex
%so
myChoice(1) := answerIndex
myChoices(2) := wrongChoices(Rand.Int(1,3))
%myChoice(1) is the correct answer's index
%myChoice(2) is a random incorrect answer's index
%and now you're ready! let the user pick between answer # myChoice(1) or myChoice(2).. you might want to keep track of the other two answers that will be crossed out, though those can be figured out since they are not in the list.
loop
put "pick an answer"
get myAnswer
if myAnswer = myChoice(1) or myAnswer = myChoice(2) then
%check if myAnswer = answerIndex, if so - user wins
exit
else
put "you can't pick that"
end if
end loop
|