This program calculates the fixed monthly payment required to amortise a loan, implementing the standard annuity formula M = P·i / (1 − (1+i)^−N). It accepts three inputs—principal borrowed, annual interest rate as a percentage, and number of monthly payments—then displays the resulting monthly payment amount. The annual interest rate is converted to a monthly rate by dividing by 1200 (lines 50). After displaying the result, the program waits for any keypress using a busy-loop on INKEY$ before cycling back to accept a new loan calculation. The SAVE at line 100 uses an inverse-video digit in the filename as an auto-run flag.
Program Analysis
Program Structure
The program is a straightforward linear input-calculate-output loop with no subroutines. Control flow is minimal: after displaying the result, a busy-loop waits for a keypress, then GOTO 20 restarts the input sequence. Line numbering is sparse and irregular, suggesting the program was edited after initial entry.
- Lines 1–4: Title display using inverse-video characters via
PRINT. - Lines 15–65: Initialisation and three
INPUTstatements collecting principal (P), annual interest rate (I), and number of payments (N). - Line 50: Interest rate conversion — annual percentage to monthly decimal.
- Line 70: Core annuity formula evaluation.
- Lines 75–85: Result display, blank line, keypress wait loop, then restart.
- Lines 100–200: Utility lines:
SAVEwith auto-run flag, and a bareRUN.
The Annuity Formula
Line 70 computes the standard fixed-payment mortgage/loan formula:
LET M=P*I/(1-((1+I)**(-N)))
This implements M = P·i / (1 − (1+i)−N), where P is the principal, I is the monthly interest rate (after conversion), and N is the total number of monthly payments. The exponentiation operator ** is used for raising to a negative power, which is valid ZX81/TS1000 BASIC.
Interest Rate Conversion
Line 50 performs LET I=(0.01*I)/12, which converts an annual percentage rate entered by the user (e.g. 12 for 12%) into a monthly decimal rate (0.01). This is mathematically correct for a simple (non-compounded) annual-to-monthly conversion and is the standard approach used in loan amortisation tables.
Key BASIC Idioms
- Input echo: After each
INPUT, the entered value is re-printed on the next line (lines 30, 45, 65). This is a common ZX81 idiom to confirm the value visually, since the system replaces the input prompt line after entry. - Keypress wait loop:
IF INKEY$="" THEN GOTO 80at line 80 is the standard busy-loop technique for waiting until any key is pressed before continuing. - Variable initialisation:
LET M=0at line 15 pre-initialises the result variable before the loop, though it is overwritten unconditionally on every pass and is not strictly necessary.
Variable Summary
| Variable | Description |
|---|---|
P | Principal (amount borrowed, in dollars) |
I | Interest rate — entered as annual %, converted to monthly decimal |
N | Number of monthly payments |
M | Calculated monthly payment amount |
Potential Anomalies
- Zero interest rate: If the user enters
I=0, line 70 will cause a division-by-zero error, asIbecomes0and the formula collapses. No error guard is present. - Zero payments: Entering
N=0will similarly produce a division-by-zero, since(1+I)**0 = 1, making the denominator zero. - Line 15 placement:
LET M=0is only executed once at program start, not on each loop iteration (the loop returns to line 20). This is harmless sinceMis always recalculated at line 70, but the initialisation serves no practical purpose within the loop.
Content
Source Code
1 REM *MONTHLY LOAN PAYMENT*
3 PRINT "%M%O%N%T%H%L%Y% %L%O%A%N% %P%A%Y%M%E%N%T"
4 PRINT
15 LET M=0
20 PRINT "AMT BORROWED = $";
25 INPUT P
30 PRINT P
35 PRINT "ANNUAL INTEREST = ";
40 INPUT I
45 PRINT I
50 LET I=(0.01*I)/12
55 PRINT "NO. OF PAYMENTS = ";
60 INPUT N
65 PRINT N
70 LET M=P*I/(1-((1+I)**(-N)))
75 PRINT "MO. PAYMENT = $ ";M
77 PRINT
80 IF INKEY$="" THEN GOTO 80
85 GOTO 20
100 SAVE "1002%7"
200 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
