This program performs bidirectional temperature conversion between Celsius and Fahrenheit. It presents a menu-driven interface where the user selects conversion direction (C→F or F→C) or terminates the program. A case counter variable K tracks the number of conversions performed during the session. The C→F formula is implemented as (9*C+160)/5 rather than the more common (9/5)*C+32, avoiding floating-point division and keeping arithmetic in integers where possible.
Program Analysis
Program Structure
The program is organised into four logical blocks:
- Title display (lines 100–160): Draws a centred ASCII banner using
TAB(15). - Menu loop (lines 180–280): Prints options, accepts input
Q, and branches or re-prompts. - C→F conversion (lines 290–360): Increments counter, accepts
C, computesF, prints result, returns to menu. - F→C conversion (lines 370–440): Mirrors the above for the reverse direction.
Line 450 uses RUN (rather than STOP) as the termination action, which restarts the program from the beginning — a common idiom when a clean reset of all variables is desired.
Key BASIC Idioms
- Case counter: Variable
Kis initialised to 0 at line 170 and incremented at lines 290 and 370, providing a running tally labelled “CASE NUMBER” in output. - Input validation loop: Lines 270–280 catch invalid menu entries and loop back to
INPUT Qat line 230 with an error message. - Return-to-menu via GOTO: Both conversion branches end with
GOTO 180, jumping past the initialisation ofKso the counter is preserved across conversions.
Notable Techniques
The conversion formulae avoid the division-first form. Instead of F = C * 9/5 + 32, line 320 uses F = (9*C + 160) / 5. This is algebraically equivalent (since 32 = 160/5) and keeps the numerator as an integer multiply-then-add before dividing, which can reduce floating-point rounding artefacts. The F→C formula at line 400, C = (5*F - 160) / 9, applies the same rearrangement (subtracting 5×32=160 before dividing by 9).
Anomalies and Points of Interest
- Line 441 (
SAVE "1010%6") appears between the last conversion branch (line 440) and the termination handler (line 450). Because both branches jump away before reaching line 441, it is unreachable during normal execution and acts solely as a save command embedded in the listing. - The
INPUT Qat line 230 accepts any numeric expression; non-numeric input would cause an error rather than triggering the polite re-prompt at line 270, since the validation only checks for values other than 1, 2, or 3 after a successful numeric entry. - The title banner at lines 100–160 uses
TAB(15)before each string, producing a consistently right-offset block of text regardless of screen width.
Variable Summary
| Variable | Purpose |
|---|---|
K | Conversion case counter |
Q | Menu selection input |
C | Celsius temperature |
F | Fahrenheit temperature |
Content
Source Code
10 REM TEMPERATURE CONVERSION
100 PRINT TAB (15),"***************"
110 PRINT TAB (15),"* *"
120 PRINT TAB (15),"* TEMPERATURE *"
130 PRINT TAB (15),"* CONVERSION *"
140 PRINT TAB (15),"* PROBLEM *"
150 PRINT TAB (15),"* *"
160 PRINT TAB (15),"***************"
170 LET K=0
180 PRINT
190 PRINT "FOR CONVERSION FROM C TO F, TYPE 1"
200 PRINT "FOR CONVERSION FROM F TO C, TYPE 2"
210 PRINT "TO TERMINATE THE PROGRAM, TYPE 3"
220 PRINT
230 INPUT Q
240 IF Q=1 THEN GOTO 290
250 IF Q=2 THEN GOTO 370
260 IF Q=3 THEN GOTO 450
270 PRINT "EXCUSE ME, ONLY 1,2, OR 3,PLEASE"
280 GOTO 230
290 LET K=K+1
300 PRINT "PLEASE TYPE IN YOUR CELSIUS TEMPERATURE"
310 INPUT C
320 LET F=(9*C+160)/5
330 PRINT
340 PRINT "CASE NUMBER";K
350 PRINT "THE EQUIVALENT FAHRENHEIT TEMPERATURE IS ";F
360 GOTO 180
370 LET K=K+1
380 PRINT "PLEASE TYPE IN YOUR FAHRENHEIT TEMPERATURE"
390 INPUT F
400 LET C=(5*F-160)/9
410 PRINT
420 PRINT "CASE NUMBER";K
430 PRINT "THE EQUIVALENT CELSIUS TEMPERATURE IS ";C
440 GOTO 180
441 SAVE "1010%6"
450 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
