You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.
Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.
rem ~~ Questions ~~
data 2 :rem this first data is used to tell the array how many questions to make room for (remember 0!)
data "What is the capital city of Spain?","Madrid","Barcelona","Lisbon","Valencia",0
data "What is the fourth prime number?","5","7","11","23",1
data "Who painted the Sistine Chapel?","Donatello","Rafael","Michaelangelo","Leonardo",2
rem we've put questions and answers on the same line to make it easier to read, and the correct answer number last of all.
rem Define the arrays
read maxq :rem the read command takes the next bit of data and loads it into the variable we supply, in this case maxq=2
rem Load data into the arrays
for i = 0 to maxq
for j = 0 to 3
rem Now we're ready to play the game!
rem === MAIN ===
rem pick a random question
qnum = rnd(maxq)
rem = print question and answers =
print "A: ";a$(qnum,0)
print "B: ";a$(qnum,1)
print "C: ";a$(qnum,2)
print "D: ";a$(qnum,3)
print "(press the corresponding letter to select an answer)"
rem = input loop =
guess = asc(upper$(inkey$()))
rem inkey$ reads the input, upper$ puts it in upper case, asc changes the letter into its ascii code value.
rem In ASCII code, every character that can be printed has its own ID number, I remember that "A" is 65, "B" is 66, and so on.
rem This is useful for evaluating the answers because the letters A-D have ASCII codes 65,66,67,68 and our answers are stored in the array
rem under 0,1,2,3, so if A (65) points to answer 0, B (66) to 1, etc. we see that the ASCII code minus 65 gives the answer it refers to.
until (guess >=65) and (guess <=68)
rem once the user gives a valid input (A-D) we leave the input loop.
rem = analyse answer =
if guess-65 = c(qnum) then msg$="CORRECT!" else "WRONG!"
print "The answer was: ";a$(c(qnum))
Login to post a reply