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.
- Lines 5–11: Title display.
- Lines 20–30: User selects conversion direction; branching on
A$="Y"jumps to the C→F path at line 80. - Lines 40–75: F→C loop: prompts for Fahrenheit input, calls
GOSUB 2000, asks if finished, repeats or stops. - Lines 80–120: C→F loop: prompts for Celsius input, calls
GOSUB 1000, asks if finished, repeats or stops. - Lines 1000–1030: Subroutine — computes and prints Celsius-to-Fahrenheit conversion.
- Lines 2000–2030: Subroutine — computes and prints Fahrenheit-to-Celsius conversion.
Conversion Formulas
| Subroutine | Line | Formula Used | Correct Formula | Status |
|---|---|---|---|---|
| C → F | 1010 | F=(9/5)*C+32 | F = (9/5)×C + 32 | ✓ Correct |
| F → C | 2010 | C=(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
PRINTthe just-entered value immediately afterINPUT, 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 viaSTOP. - Variable reuse: The variable
Cserves double duty — it holds the Celsius input in the main block and is also written by the F→C subroutine at line 2010. Equally,Fis 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
PRINTto emit a blank line — a standard idiom for spacing output. - The label in the
SAVEcommand at line 3000 is an unusual alphanumeric string ("1004%5"), suggesting a filing or catalogue convention rather than a descriptive name.
Content
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.
