Temperature Conversion

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

This program performs bidirectional temperature conversion between Celsius and Fahrenheit. At startup the user chooses which direction to convert; Celsius-to-Fahrenheit conversions use the subroutine at line 1000 (formula F = (9/5)×C + 32), while Fahrenheit-to-Celsius conversions use the subroutine at line 2000. After each conversion the user is asked whether they are finished, allowing repeated conversions in a loop via GOTO. The program contains a notable bug at line 2010: the Fahrenheit-to-Celsius formula incorrectly subtracts 12 instead of 32, giving C = (F−12)×(5/9) rather than the correct C = (F−32)×(5/9).


Program Analysis

Program Structure

The program is divided into three logical regions: a main menu and dispatch block (lines 5–120), a Celsius-to-Fahrenheit subroutine (lines 1000–1030), and a Fahrenheit-to-Celsius subroutine (lines 2000–2030). Lines 3000–3010 handle saving and restarting the program.

  1. Lines 5–11: Title display.
  2. Lines 20–30: User selects conversion direction; branching on A$="Y" jumps to the C→F path at line 80.
  3. Lines 40–75: F→C loop: prompts for Fahrenheit input, calls GOSUB 2000, asks if finished, repeats or stops.
  4. Lines 80–120: C→F loop: prompts for Celsius input, calls GOSUB 1000, asks if finished, repeats or stops.
  5. Lines 1000–1030: Subroutine — computes and prints Celsius-to-Fahrenheit conversion.
  6. Lines 2000–2030: Subroutine — computes and prints Fahrenheit-to-Celsius conversion.

Conversion Formulas

SubroutineLineFormula UsedCorrect FormulaStatus
C → F1010F=(9/5)*C+32F = (9/5)×C + 32✓ Correct
F → C2010C=(F-12)*(5/9)C = (F−32)×(5/9)✗ Bug: −12 should be −32

Bug: Incorrect Fahrenheit-to-Celsius Constant

Line 2010 reads LET C=(F-12)*(5/9). The correct offset is 32, not 12. This means every Fahrenheit-to-Celsius result will be wrong; for example, 32°F would yield approximately 11.1°C instead of the correct 0°C. The C→F subroutine at line 1010 is correct, making the error asymmetric.

Key BASIC Idioms and Techniques

  • GOSUB/RETURN structure: Conversion logic is cleanly separated into subroutines at lines 1000 and 2000, keeping the main loop concise.
  • Input echo: Lines 42 and 82 each PRINT the just-entered value immediately after INPUT, providing visual confirmation of the entered number.
  • Y/N loop control: Continuation is handled by testing for "N" rather than "Y" — the program exits on anything other than an explicit “N”, meaning any unexpected input also terminates the loop gracefully via STOP.
  • Variable reuse: The variable C serves double duty — it holds the Celsius input in the main block and is also written by the F→C subroutine at line 2010. Equally, F is used both as direct input and as output from the C→F subroutine. This creates no conflict given the program’s linear flow but could cause issues if the structure were extended.

Notable Anomalies

  • The program uses three separate input variables for the Y/N prompts (A$, B$, C$) where a single variable would suffice, slightly inflating memory use.
  • Line 11 uses a bare PRINT to emit a blank line — a standard idiom for spacing output.
  • The label in the SAVE command at line 3000 is an unusual alphanumeric string ("1004%5"), suggesting a filing or catalogue convention rather than a descriptive name.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10001 – 10050.

Related Products

Related Articles

Related Content

Image Gallery

Temperature Conversion

Source Code

   5 REM TEMP CONVERSION
  10 PRINT "TEMPERATURE CONVERSION"
  11 PRINT 
  20 PRINT "DO YOU WISH TO CONVERT C TO F(Y/N)"
  21 INPUT A$
  30 IF A$="Y" THEN GOTO 80
  40 PRINT "ENTER DEGREES F"
  41 INPUT F
  42 PRINT F
  50 GOSUB 2000
  60 PRINT "ARE YOU FINISHED(Y/N)"
  61 INPUT B$
  70 IF B$="N" THEN GOTO 40
  75 STOP 
  80 PRINT "ENTER DEGREES C"
  81 INPUT C
  82 PRINT C
  90 GOSUB 1000
 100 PRINT "ARE YOU FINISHED(Y/N)"
 101 INPUT C$
 110 IF C$="N" THEN GOTO 80
 120 STOP 
\n1000 REM CEL TO FAHR CONV
\n1010 LET F=(9/5)*C+32
\n1020 PRINT C;" DEGREES CELSIUS=   ";F;" DEGREES FAHRENHEIT"
\n1030 RETURN 
\n2000 REM FAHR TO CEL CONV
\n2010 LET C=(F-12)*(5/9)
\n2020 PRINT F;" DEGREES FAHRENHEIT=  ";C;"  DEGREES CELSIUS"
\n2030 RETURN 
\n3000 SAVE "1004%5"
\n3010 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