Temperature Conversion

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

This program converts temperatures between Fahrenheit, Celsius, and Kelvin. The user enters a numeric temperature and selects a unit (F, C, or K); an input validation loop at line 70 rejects anything other than these three letters before proceeding. Two subroutines handle the conversions: lines 200–220 convert Fahrenheit to Celsius using the standard (T−32)×5/9 formula, while lines 300–340 handle both Celsius-to-Fahrenheit and Kelvin-to-Fahrenheit by first normalising Kelvin to Celsius before applying the C×9/5+32 formula. After displaying the result, the program waits for any key press via INPUT A$ before clearing the screen and looping back to the start.


Program Analysis

Program Structure

The program is organised into a main loop and two conversion subroutines:

  1. Lines 10–150: Main loop — prompts for temperature and unit, dispatches to a subroutine, displays the result, waits for a keypress, then repeats.
  2. Lines 200–220: Fahrenheit → Celsius subroutine.
  3. Lines 300–340: Celsius or Kelvin → Fahrenheit subroutine.

Conversion Logic

Input unitSubroutineFormulaOutput unit
F200(T − 32) × 5 / 9C
C300C × 9/5 + 32F
K300(T − 273) × 9/5 + 32F

Note that Kelvin converts to Fahrenheit only; there is no direct K→C path presented to the user as a final result, though the intermediate Celsius value is computed in C at line 310.

Input Validation

Line 70 implements a validation loop by re-routing to line 60 (GOTO 60) if the entered string is not one of the three accepted unit codes. This is a common BASIC idiom that keeps the user in a tight loop until valid input is received, without any explicit error message being printed.

Key BASIC Idioms

  • Subroutine dispatch via consecutive IF statements: Lines 90 and 100 each test Q$ independently and call the appropriate GOSUB. Because the two conditions are mutually exclusive (validated at line 70), only one subroutine fires per pass.
  • Pause-via-INPUT: Line 130 uses INPUT A$ as a “press ENTER to continue” gate, a standard idiom where the variable A$ is never actually used.
  • Shared subroutine for two input units: The Kelvin branch shares the Celsius→Fahrenheit subroutine (line 300) by adjusting the intermediate variable C at line 310, avoiding code duplication.

Notable Anomalies

  • The Kelvin conversion uses 273 as the offset rather than the more precise 273.15. This introduces a small but non-trivial rounding error for scientific use.
  • The program only converts in one direction per unit pair: F→C, C→F, and K→F. There is no C→K, K→C, or F→K path.
  • Lines 350 and 360 (SAVE "1017%2" and RUN) appear to be a save-and-restart tail appended to the listing and are not part of the interactive program flow.

Appears On

Tape 1003 of the Timex Sinclair Public Domain Library. Assembled by Tim Ward from many sources.

Image Gallery

Source Code

  10 REM "TEMP CONV"
  20 PRINT "ENTER TEMPERATURE"
  30 INPUT T
  40 PRINT T
  50 PRINT "C, F, OR K";
  60 INPUT Q$
  70 IF Q$<>"F" AND Q$<>"C" AND Q$<>"K" THEN GOTO 60
  80 PRINT Q$
  90 IF Q$="F" THEN GOSUB 200
 100 IF Q$="C" OR Q$="K" THEN GOSUB 300
 110 CLS 
 120 PRINT T;" ";Q$;"=";N;" ";R$
 130 INPUT A$
 140 CLS 
 150 GOTO 10
 200 LET N=(T-32)*5/9
 210 LET R$="C"
 220 RETURN 
 300 LET C=T
 310 IF Q$="K" THEN LET C=T-273
 320 LET N=C*9/5+32
 330 LET R$="F"
 340 RETURN 
 350 SAVE "1017%2"
 360 RUN 

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