Math Program

This file is part of Timex Sinclair Public Domain Library Tape 1002 . Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Education

This program is a simple arithmetic drill that asks the user their name, prompts for two numbers, and tests whether the user can correctly add them together. On a wrong answer the player is offered a retry loop before being asked if they want a new problem. The program personalises feedback using the stored name string and relies entirely on string comparison for yes/no branching. There is a notable structural anomaly: line 200 is missing, so the GOTO 200 on line 162 jumps to a non-existent line, bypassing the “GOOD FOR YOU” message on line 201.


Program Analysis

Program Structure

The program is organised as a linear question-and-answer drill with two nested retry loops. The overall flow is:

  1. Lines 10–111: Title REM and name input.
  2. Lines 130–141: Input of two operands (N1, N2).
  3. Lines 150–175: Pose the addition question, accept answer A, branch on correctness, offer retry.
  4. Lines 201–214: Print optional praise, ask to play again, loop back to line 120 or fall through to goodbye.
  5. Lines 301–900: Farewell message and STOP.
  6. Lines 910–920: Utility lines (SAVE and RUN).

Key BASIC Idioms

Yes/no decisions are handled by storing the user’s response in A$ and comparing with the string literal "YES". This is a common early-BASIC idiom but is case-sensitive, so entries like "yes" or "Yes" will silently fall through to the negative branch rather than looping — a usability issue on a keyboard where CAPS LOCK behaviour varies.

The program uses semicolons in PRINT statements to keep prompts and inputs on the same line (e.g. lines 130/131, 140/141, 150/151), which gives a cleaner appearance than separate lines would.

Notable Bug: Missing Line 200

Line 162 reads IF A=(N1+N2) THEN GOTO 200, but line 200 does not exist in the listing. The next line after 175 is 201. When the user answers correctly, execution jumps to line 200, which is absent; on most Sinclair-family interpreters this causes an error rather than falling through to line 201. The “GOOD FOR YOU” message at line 201 is therefore unreachable via the correct-answer path. This appears to be a simple off-by-one error in line numbering — the author likely intended GOTO 201.

Control Flow Anomalies

LineConditionDestinationNotes
162Answer correct200Line 200 does not exist — runtime error
173A$=”YES” (retry)150Re-poses same question
175Unconditional210Skips praise, goes straight to “try another”
214A$=”YES” (new problem)120Loops back for new operands

Variable Summary

  • N$ — Player’s name, used in praise and goodbye messages.
  • N1, N2 — The two operands for the addition problem.
  • A — The player’s numeric answer.
  • A$ — The player’s yes/no string response (reused for both retry and new-problem prompts).

Line Numbering

The line numbers jump non-uniformly (10, 110–111, 120, 130–131, …, 900, 910, 920), suggesting the program was either written with expansion space in mind or was edited after initial entry. The large gap between line 10 and line 110 leaves room for additional setup code that was never written. The utility SAVE and RUN lines at 910–920 are placed well after the STOP at line 900, ensuring they are not reached during normal execution but are available for direct entry.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10051 – 10121.

Related Products

Related Articles

Related Content

Image Gallery

Math Program

Source Code

  10 REM MATH PROGRAM
 110 PRINT "WHAT IS YOUR NAME?"
 111 INPUT N$
 120 PRINT 
 130 PRINT "ENTER A NUMBER,PLEASE";
 131 INPUT N1
 140 PRINT " AND ANOTHER";
 141 INPUT N2
 150 PRINT "  WHAT IS ";N1;" + ";N2;
 151 INPUT A
 162 IF A=(N1+N2) THEN GOTO 200
 171 PRINT " SORRY---WRONG ANSWER.WANT TO TRY AGAIN?";
 172 INPUT A$
 173 IF A$="YES" THEN GOTO 150
 175 GOTO 210
 201 PRINT " GOOD FOR YOU, ";N$
 210 PRINT 
 211 PRINT " WANT TO TRY ANOTHER PROBLEM";
 212 INPUT A$
 214 IF A$="YES" THEN GOTO 120
 301 PRINT "  O.K. ";N$;"--GOODBYE"
 900 STOP 
 910 SAVE "1010%2"
 920 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top