This program is a simple astronomical unit-conversion tool that converts between light-years, kilometres, and miles. It presents a text menu using INKEY$ for keypress detection without requiring ENTER, looping back to the menu after each conversion. The conversion constants used are 9.4830912×10¹² km and 5.892792872×10¹² miles per light-year, the latter being slightly low compared to the accepted value of approximately 5.879×10¹² miles, suggesting a minor inaccuracy in the miles constant. The program uses `10**12` (exponentiation) for expressing large astronomical constants inline, and the menu-driven flow relies on string comparison with `C$>”1″` to branch between options 2 and 3 versus option 1.
Program Analysis
Program Structure
The program is divided into several logical blocks, navigated by menu choice stored in C$:
- Lines 10–130: Initialisation, menu display, and INKEY$ input loop.
- Lines 300–390: Light-years → km and miles conversion (option 1).
- Lines 400–460: km → light-years conversion (option 2).
- Lines 500–530: Miles → light-years conversion (option 3).
- Lines 540–560: Shared output and loop-back to menu.
- Lines 600–700: SAVE and RUN utility lines, not part of normal execution flow.
Menu Input and Branching
The program uses a tight INKEY$ polling loop at lines 120–130 to detect a keypress without requiring ENTER. Only three choices are valid (1, 2, 3), but the branching logic is coarse: line 140 uses IF C$>"1" to divert anything greater than “1” (i.e., “2”, “3”, or any higher character) to line 400. Within that block, line 410 specifically checks for “3” to divert to the miles input. Any character other than “1”, “2”, or “3” will enter the km conversion path silently, which is a minor robustness issue.
Conversion Constants
The program defines its conversion factors inline using the exponentiation operator **:
| Conversion | Constant Used | Accepted Value |
|---|---|---|
| Light-year → km | 9.4830912 × 10¹² | 9.4607 × 10¹² km |
| Light-year → miles | 5.892792872 × 10¹² | 5.8786 × 10¹² miles |
Both constants are somewhat inaccurate compared to the modern IAU definition, with the km value about 0.24% too high and the miles value about 0.24% too high as well — consistent with each other but diverging from accepted values, suggesting the author used a slightly off source figure for the light-year.
Key BASIC Idioms
- INKEY$ polling loop: Lines
120–130form the classicIF INKEY$="" THEN GOTObusy-wait for a single keypress, avoiding the need for INPUT and ENTER. - Exponentiation with
**: Used at lines340,350,450, and530to express 10¹² compactly inline. - Shared output path: Lines
540–560handle the final light-year output for all three reverse-conversion branches, reducing code duplication. - GOTO 10 loop: Line
560returns to the menu start rather than a dedicated restart line, re-running variable initialisation (M=0,K=0) each cycle.
Notable Anomalies
- Line
300is reached from the menu only whenC$="1", but there is no explicitGOTO 300— execution falls through from line140when the condition is false (i.e., whenC$is not greater than “1”). This works correctly but is easy to misread. - After completing a light-year → km/miles conversion (option 1), execution falls into line
400(CLS) and then line410, which checksC$again. SinceC$is still “1” at this point, neither branch at410triggers, so it falls through to the km input at line420— meaning option 1 unexpectedly prompts for a km value after displaying its results. This is a genuine bug. - The
PRINT Lat line330and similar echo prints (lines440,520) re-display the just-entered value, a common idiom to confirm INPUT on machines without line-editing feedback.
Content
Source Code
5 REM **ASTRONOMY**
10 CLEAR
20 LET M=0
30 LET K=0
40 PRINT "CONVERSIONS"
50 FOR P=1 TO 11
60 PRINT "*";
70 NEXT P
80 PRINT
90 PRINT "1/LTYRS TO MILES"
100 PRINT "2/KM TO LTYRS"
110 PRINT "3/MILES TO LTYRS"
120 LET C$=INKEY$
130 IF C$="" THEN GOTO 120
140 IF C$>"1" THEN GOTO 400
300 CLS
310 PRINT "LTYRS: ";
320 INPUT L
330 PRINT L
340 LET K=L*(9.4830912*10**12)
350 LET M=L*(5.892792872*10**12)
360 PRINT "KM: ";K
370 PRINT "MILES: ";M
400 CLS
410 IF C$="3" THEN GOTO 500
420 PRINT "KM: ";
430 INPUT K
440 PRINT K
450 LET L=K/(9.4830912*(10**12))
460 GOTO 540
500 PRINT "MILES: ";
510 INPUT M
520 PRINT M
530 LET L=M/(5.892792872*(10**12))
540 PRINT "LTYRS: ";L
550 PRINT
560 GOTO 10
600 SAVE "1006%3"
700 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
