This program converts temperatures from Fahrenheit to Celsius and Kelvin across a user-defined range and step size. The user inputs a low temperature, a high temperature, and a step interval; the program then prints a three-column table of F, C, and K values. A decorative border effect is produced by printing 32 (then 21) random block-graphic characters using CHR$(10*RND+128), which selects from the Spectrum/TS2068 block graphics in the range 128–137. The program handles reversed input order (high entered before low) by swapping A and B into E and F before the loop at line 300.
Program Analysis
Program Structure
The program is laid out in three broad phases:
- Title / decoration (lines 10–60): Clears, prints a title, then draws a random block-graphic border of 32 characters.
- Input (lines 70–210): Asks for the lowest Fahrenheit temperature, the highest, and the step size. Lines 160–190 reorder inputs so that
Falways holds the lower bound andEthe upper, regardless of which the user entered first. - Output (lines 220–360): Clears the screen, prints a column header (F, C, K), draws a second random border of 21 characters, then loops from
FtoE+Zin steps ofZ, computing and printing each row. On exit it saves and re-runs.
Temperature Conversion
The Celsius conversion at line 310 uses the standard formula C = 5*(D-32)/9. Kelvin is derived at line 320 as K = C+273, using the common rounded value rather than the more precise 273.15. Results are printed with TAB 8 for the Fahrenheit column and TAB 24 for Kelvin; the comma separator after C advances to the next print zone, placing Kelvin approximately at column 24.
Input Reordering Logic
Lines 160–190 implement a conditional swap without a dedicated temporary variable, using two separate flag-style assignments:
- Line 160:
IF B<A THEN LET E=A— E gets the larger value when B is smaller - Line 170:
IF A<B THEN LET F=A— F gets the smaller value when A is smaller - Line 180:
IF B<A THEN LET F=B— F gets the smaller value when B is smaller - Line 190:
IF A<B THEN LET E=B— E gets the larger value when B is larger
This works correctly for the case where A ≠ B, but if A = B neither branch fires and E and F remain uninitialised, which would cause an error at line 300.
Decorative Block Graphics
The border effect at lines 40–60 and 260–280 selects a random starting character with H = 10*RND (giving a value in [0,10)), adds 128, and prints that single CHR$ character in a loop. Since block graphic characters occupy codes 128–143, this lands within the block graphic set. However, using the same character repeated rather than cycling through them produces a uniform stripe rather than a varied pattern. A fresh random offset is chosen each time the program loops (via RUN at line 360), giving visual variety between runs.
Variable Usage
| Variable | Purpose |
|---|---|
A | First temperature entered by user |
B | Second temperature entered by user |
E | Upper bound of range (after reordering) |
F | Lower bound of range (after reordering) |
Z | Step size |
D | Loop variable (current Fahrenheit value) |
C | Celsius result |
K | Kelvin result (also reused as decoration RND seed at line 30) |
H | Second decoration CHR$ offset |
S, U | Loop counters for decoration loops |
Notable Anomalies
- Variable
Kis used first as a decoration seed (line 30) and then overwritten as the Kelvin temperature (line 320). This is harmless but slightly confusing. - Line numbers 80–110 and 240 are absent, suggesting the program was edited and some lines deleted.
- The loop at line 300 runs to
E+Zrather thanE, which means the table always includes one extra row beyond the requested upper bound. - The
SAVE "1005%0"at line 357 (where%0is an inverse0) is an auto-run save; line 360 then immediatelyRUNs the program, creating a continuous loop.
Content
Source Code
5 REM CONVERSION PROGRAM
10 RAND
20 PRINT " A DEGREE OF CONVERSION"
30 LET K=10*RND
40 FOR S=1 TO 32
50 PRINT CHR$ (K+128);
60 NEXT S
70 PRINT AT 5,0;"WHAT IS THE LOWEST TEMP,(F)YOU"
120 PRINT "WANT TO CONVERT?"
130 INPUT A
140 PRINT ,"AND HIGHEST?"
150 INPUT B
160 IF B<A THEN LET E=A
170 IF A<B THEN LET F=A
180 IF B<A THEN LET F=B
190 IF A<B THEN LET E=B
200 PRINT "IN WHAT DEGREE STEPS?"
210 INPUT Z
220 CLS
230 PRINT TAB 8;"F","C";TAB 24;"K"
250 LET H=10*RND
260 FOR U=1 TO 21
270 PRINT CHR$ (H+128);
280 NEXT U
290 PRINT
300 FOR D=F TO E+Z STEP Z
310 LET C=5*(D-32)/9
320 LET K=C+273
330 PRINT TAB 8;D,C;TAB 24;K
350 NEXT D
357 SAVE "1005%0"
360 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
