Presidents is an educational quiz program that tests knowledge of U.S. presidents and their terms of office. The program stores president names in array A$() and corresponding term dates in array B$(), supporting two quiz modes: identifying a president given their term, or identifying the term given a president’s name. Answer comparison is performed as string matching, with a padding loop at lines 341–343 that equalizes string lengths before comparing with C$=E$. Players receive two attempts per question, and a scoreboard at the end calculates the percentage correct using rounding via INT(((R/Q)*100)+.5).
Program Analysis
Program Structure
The program is organized into clearly separated functional blocks:
- Lines 5–40: Initialization, welcome screen, and instructions branch (Y/N input)
- Lines 100–185: Instructions display, waits for any keypress to proceed
- Lines 200–234: Quiz configuration — mode selection (presidents or terms) and question count
- Lines 240–420: Main quiz loop — question display, input, answer checking, scoring
- Lines 500–580: Scoreboard and session restart logic
- Lines 600–720: Data retrieval subroutines for the two quiz modes
- Lines 998–999: Clean exit via CLS and STOP
- Line 1000: SAVE line with program name
- Lines 1100–1120: “Press any key to continue” subroutine
Note that the data arrays A$() and B$() holding president names and term dates are not shown in this listing — they would be defined in lines between those shown, likely loaded from tape or defined in a companion segment.
Quiz Modes and Data Subroutines
Two subroutines handle the bidirectional nature of the quiz. When N=1 (guess the president), subroutine at line 600 sets C$ (correct answer) to the name A$(A) and the displayed clue D$ to the term B$(A). When N=2 (guess the term), subroutine at line 700 reverses the assignment. The random question selector A is computed at line 250 as INT(RND*40)+1, implying the data arrays contain exactly 40 entries covering all presidents available at the time of writing.
Answer Comparison and String Padding
Answer matching is done by direct string equality (C$=E$ at line 350). Because the user’s input E$ may be shorter than the stored answer C$, lines 341–343 pad E$ with trailing spaces until its length matches C$:
FOR Z=1 TO (LEN C$-LEN E$)LET E$=E$+" "NEXT Z
This ensures the comparison works correctly even if the stored strings have trailing spaces. However, this technique does not handle the case where E$ is longer than C$, which would make LEN C$-LEN E$ negative and cause the FOR loop to execute zero times — effectively leaving E$ longer than C$ and guaranteeing a mismatch. This is a minor but real edge-case bug.
Two-Attempt Logic
Each question allows two attempts, controlled by the variable T initialized to 1 at line 290. On a wrong first answer, T is set to 2 at line 365 and the player is looped back. On a second wrong answer, the condition at line 355 (IF T=2 THEN GOTO 380) routes to the “sorry” message and reveals the correct answer. The wrong-answer counter W is incremented at line 383, though W is never displayed on the scoreboard — it is tracked but unused in the final output.
Screen Clearing via Z$
Lines 300–304 print Z$ three times at successive screen rows (5, 6, 7) to blank out the feedback area before each question attempt. The variable Z$ is used as a blank string “eraser.” Its value is never explicitly set in this listing, implying it is initialized as an empty or space-filled string in the missing data section, or relies on the default empty string from RAND 0 / program start.
Scoreboard and Percentage Calculation
The final scoreboard (lines 500–540) computes the percentage correct with rounding:
LET P=INT(((R/Q)*100)+.5)
Adding 0.5 before truncating with INT achieves standard rounding to the nearest whole number. The scoreboard displays questions asked (Q), correct answers (R), and the rounded percentage (P). The wrong-answer count W is silently discarded.
Key Input Handling
The program uses two distinct patterns for key detection:
- Spin-wait on non-empty INKEY$: used at lines 185 and 1110 to pause until any key is pressed (
IF INKEY$="" THEN GOTO self). - Explicit key value check: used at lines 30/35 and 560/570 to branch on “Y” or “N” responses, with a fall-through GOTO to retry.
Notable Anomalies
| Line(s) | Issue |
|---|---|
| 341–343 | String padding loop does not handle E$ longer than C$; negative loop count silently skips, causing guaranteed mismatch on over-long input. |
| 234, 383 | Wrong-answer counter W is incremented but never displayed or used in any calculation. |
| 300–304 | Z$ is used as a screen-clearing string but is never initialized in this listing; relies on external or implicit initialization. |
| 250, 420 | Questions are picked randomly with replacement; the same president can appear multiple times in a session with no duplicate-prevention logic. |
Content
Image Gallery
Source Code
5 CLS
6 SLOW
7 RAND 0
10 PRINT AT 3,5;"WELCOME TO THE U.S. ";AT 5,7;"PRESIDENTS QUIZ"
20 PRINT AT 8,3;"DO YOU NEED INSTRUCTIONS";AT 10,12;"Y/N"
25 PRINT AT 20,7;"(C) 1982 TIMEX"
30 IF INKEY$ ="Y" THEN GOTO 100
35 IF INKEY$ ="N" THEN GOTO 200
40 GOTO 30
100 CLS
110 PRINT AT 2,0;"IN THIS HISTORY QUIZ PROGRAM"
112 PRINT AT 3,0;"YOU WILL TRY TO FIND EITHER:"
114 PRINT AT 5,0;"* THE TERM OF A PRESIDENT"
115 PRINT AT 6,0;"(GIVEN HIS NAME)OR"
116 PRINT AT 7,0;"* THE NAME OF A PRESIDENT"
117 PRINT AT 8,0;"(GIVEN THE TERM)"
118 PRINT AT 10,0;"YOU WILL GET 2 CHANCES TO";AT 11,0;"ANSWER EACH QUESTION"
120 PRINT AT 12,0;"AND A SUMMARY AT THE END"
130 PRINT AT 13,0;"WHEN ENTERING A NAME, TYPE";AT 14,0;"BOTH FIRST AND LAST NAMES"
140 PRINT AT 15,0;"ENTER DATES IN THE FORM";AT 16,0;"YEAR-YEAR"
150 PRINT AT 18,0;"REMEMBER TO PRESS [E][N][T][E][R] "
180 PRINT AT 20,1;"*****PRESS ANY KEY TO START****"
185 IF INKEY$ ="" THEN GOTO 185
200 CLS
210 PRINT AT 3,0;"WOULD YOU LIKE TO GUESS"
211 PRINT AT 4,0;"(1)PRESIDENTS";AT 5,0;"(2)TERMS"
212 INPUT N
213 IF N<1 OR N>2 THEN GOTO 200
214 PRINT AT 6,0;N
215 IF N=1 THEN LET P$="WHO SERVED FROM"
216 IF N=2 THEN LET P$="WHEN WAS OUR PRESIDENT:"
220 PRINT AT 7,0;"HOW MANY QUESTIONS ?"
222 INPUT Q
223 IF Q<1 OR Q>1000 THEN GOTO 220
224 PRINT AT 8,0;Q
230 LET M=1
232 LET R=0
234 LET W=0
240 CLS
242 PRINT AT 1,1;"QUESTION NUMBER "
244 PRINT AT 3,1;P$
250 LET A=INT (RND*40)+1
260 IF N=1 THEN GOSUB 600
270 IF N=2 THEN GOSUB 700
290 LET T=1
300 PRINT AT 5,0;Z$
302 PRINT AT 6,0;Z$
304 PRINT AT 7,0;Z$
310 PRINT AT 1,18;" ";M;" "
322 PRINT AT 4,1;D$
330 INPUT E$
340 PRINT AT 5,1;E$
341 FOR Z=1 TO (LEN C$-LEN E$)
342 LET E$=E$+" "
343 NEXT Z
350 IF C$=E$ THEN GOTO 390
355 IF T=2 THEN GOTO 380
360 PRINT AT 6,0;"NOT CORRECT TRY AGAIN"
365 LET T=2
367 GOSUB 1100
370 GOTO 300
380 PRINT AT 6,0;"SORRY, THE CORRECT ANSWER WAS"
382 PRINT AT 7,0;C$
383 LET W=W+1
384 GOSUB 1100
385 GOTO 400
390 PRINT AT 6,0;"*** CORRECT ***"
395 LET R=R+1
397 GOSUB 1100
400 LET M=M+1
410 IF M>Q THEN GOTO 500
420 GOTO 250
500 CLS
505 LET P=INT (((R/Q)*100)+.5)
510 PRINT AT 2,0;"████SCOREBOARD████"
520 PRINT AT 4,0;"NUMBER OF QUESTIONS ";Q
530 PRINT AT 6,0;"NUMBER CORRECT ";R
540 PRINT AT 8,0;"PERCENT CORRECT ";P
550 PRINT AT 20,0;"ANOTHER SESSION ? (Y/N)"
560 IF INKEY$ ="Y" THEN GOTO 5
570 IF INKEY$ ="N" THEN GOTO 998
580 GOTO 560
600 LET C$=A$(A)
610 LET D$=B$(A)
620 RETURN
700 LET C$=B$(A)
710 LET D$=A$(A)
720 RETURN
998 CLS
999 STOP
1000 SAVE "PRES [1]"
1010 GOTO 5
1100 PRINT AT 20,1;"**PRESS ANY KEY TO CONTINUE**"
1110 IF INKEY$ ="" THEN GOTO 1110
1115 PRINT AT 20,0;Z$
1120 RETURN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.