QUIZMASTER is a question-and-answer quiz program that lets users enter their own questions and answers, then tests them in random order. The program stores up to m questions in string arrays c$() for clues and a$() for answers, tracking answer lengths in l(). It awards two points for a correct first attempt and one point for a correct answer after a hint; the hint reveals only the first and last characters of the answer, padding the middle with dashes. After entry, the quiz data is saved as a self-running BASIC file via SAVE p$ LINE 20, so the saved program restarts directly into the quiz loop.
Program Structure
The program is divided into two distinct phases separated by a STOP at line 9997:
- Entry phase (lines 500–670): The user inputs questions and answers, which are stored in arrays, then the whole program is saved with
SAVE p$ LINE 20so subsequent loads jump straight into the quiz. - Quiz phase (lines 10–170): The saved file auto-runs from line 20, skipping the entry phase entirely. Questions are presented in random order using a shrinking index array.
The REM at line 15 (****run 500) is a human reminder to manually GO TO 500 to begin data entry during authoring. Line 9998 saves the blank template as "QUIZMASTER".
Randomisation Without Replacement
Rather than re-rolling until an unseen question is found, the program maintains a packed index array y() of remaining question numbers. At each round (lines 60–80), a random position z within the remaining x entries is chosen, the corresponding question index q is retrieved, and then the slot is removed by shifting all subsequent entries down one position. This guarantees every question appears exactly once with O(n) removal cost.
Scoring and Hint System
Variable t acts as a score token, initialised to 2 at line 90. A correct first-attempt answer adds 2 to score s; after a hint is shown, t is set to 1 (line 310), so a correct second attempt adds only 1. Maximum possible score is therefore m*2, which is shown at line 160.
The hint (line 330) constructs a masked string: a$(q,1) (first character) + a substring of dashes of length l(q)-2 from the 15-dash string b$ + a$(q,l(q)) (last character). This cleverly avoids any loop.
Key BASIC Idioms
- Partial-string comparison (line 110):
i$<>a$(q)( TO l(q))compares the user’s input only against the stored answer up to its recorded lengthl(q), working around the fixed-length DIM padding with spaces. - Keypress debounce (lines 460–480): The subroutine first waits for
INKEY$to be empty (key up), then waits for a non-empty value (key down), then reads it — preventing repeated or held keys from triggering multiple events. - Screen clearing with
e$(lines 210–280): A 32-space string is PRINTed over old text at specificATpositions instead of issuing a fullCLS, preserving other screen content. - Double-apostrophe newlines in PRINT (line 540):
PRINT "Question ";q''uses two consecutive'tokens to print two blank lines after the question number.
Data Storage
| Array | DIM | Purpose |
|---|---|---|
c$(m,64) | m × 64 chars | Question/clue text |
a$(m,15) | m × 15 chars | Answer text (max 15 chars) |
l(m) | m numeric | True length of each answer (avoids trailing-space issue) |
y(m) | m numeric | Remaining question indices for random selection |
Content
Image Gallery
Source Code
10 REM INITIALIZATION
15 REM ****run 500
20 LET s=0: LET x=m: LET b$="---------------": LET e$=" "
30 FOR n=1 TO m: LET y(n)=n: NEXT n
40 GO SUB 400: CLS : FOR n=1 TO m: PRINT AT 10,8;a$(n): PAUSE 50: CLS : NEXT n
50 REM MAIN PROGRAM
60 LET z=INT (RND*x+1): LET q=y(z)
70 LET x=x-1
80 FOR n=z TO x: LET y(n)=y(n+1): NEXT n
90 CLS : LET t=2
100 PRINT AT 3,0;c$(q): INPUT i$
110 IF i$<>a$(q)( TO l(q)) THEN GO TO 240
120 LET s=s+t: GO TO 210
130 GO SUB 410: CLS
140 IF x=0 THEN GO TO 60
150 REM FINAL SCORE
160 PRINT AT 5,0;"Your score was ";s;" out of ";m*2
170 STOP
200 REM PRAISE
210 PRINT AT 7,0;"Well done, ";i$;" was right.";AT 9,15;e$
220 GO TO 130
230 REM WRONG ANSWER
240 IF i$="" THEN GO TO 260
245 PRINT AT 7,0;i$;" was wrong.";e$;AT 9,0;e$
250 GO SUB 410
260 IF t=2 THEN GO TO 310
270 PRINT AT 7,0;"The right answer was:";e$;AT 9,15;a$(q)
280 GO TO 130
300 REM HINT/SECOND TRY
310 LET t=1
320 PRINT AT 7,0;"Here is a hint:";e$;AT 21,0;e$
330 PRINT AT 9,15;a$(q,1)+b$(1 TO l(q)-2)+a$(q,l(q))
340 GO TO 100
400 REM ENTER TO CONTINUE
410 PRINT AT 21,0;"Press ENTER to continue."
420 GO SUB 460
430 IF CODE k$=13 THEN RETURN
440 GO TO 420
450 REM SINGLE KEY INPUT
460 IF INKEY$<>"" THEN GO TO 460
470 IF INKEY$="" THEN GO TO 470
480 LET k$=INKEY$: RETURN
500 REM ENTER QUESTIONS/ANSWERS
510 PRINT "How many questions?": INPUT m
520 DIM c$(m,64): DIM a$(m,15): DIM l(m): DIM y(m)
530 FOR q=1 TO m
540 CLS : PRINT "Question ";q''
550 PRINT "Type in the question or clue.": INPUT c$(q)
560 PRINT 'c$(q)''"Type in the answer.": INPUT i$
570 PRINT 'i$;AT 20,0;"If satisfactory, type s."," To delete, type d."
580 GO SUB 460
590 IF k$="d" THEN GO TO 540
600 IF k$<>"s" THEN GO TO 580
610 LET l(q)=LEN i$: LET a$(q)=i$
620 NEXT q
650 REM SAVE AND RUN
660 CLS : INPUT "What is the program name?";p$
670 SAVE p$ LINE 20
9997 STOP
9998 SAVE "QUIZMASTER" LINE 1
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.