This program calculates the effective annual interest rate on a loan using the actuarial approximation formula R = 2·P·((N·A)−B) / (B·(N+1)), where P is the number of payments per year, N is the total number of payments, A is the individual payment amount, and B is the borrowed principal. The result is rounded to one decimal place using the INT(x·1000+0.5)/10 idiom and displayed as a percentage. After each calculation the user is prompted to run another, looping back to line 10 if the answer is not “N”. Input values are echoed to the screen immediately after entry (lines 31, 51, 71, 91), a common ZX81 workaround to confirm what was typed since the display scrolls after INPUT.
Program Analysis
Program Structure
The program is a straightforward single-file BASIC application with a simple input–calculate–display–repeat loop. There are no subroutines; control flow is handled entirely by a conditional GOTO and an unconditional GOTO.
- Lines 10–91 — Input phase: collect P, N, A, and B with immediate echo prints.
- Lines 120–130 — Calculation: apply the interest-rate formula and round the result.
- Lines 135–150 — Output: display the effective rate as a percentage.
- Lines 160–190 — Loop control: prompt for another calculation or exit.
- Lines 200–210 — Save and list the program on exit.
The Interest-Rate Formula
Line 120 implements the actuarial approximation (sometimes called the N-ratio or constant-ratio method) for effective annual interest:
R = 2 * P * ((N * A) - B) / (B * (N + 1))
| Variable | Meaning |
|---|---|
P | Number of payment periods per year |
N | Total number of payments |
A | Amount of each payment |
B | Principal borrowed |
R | Effective annual interest rate (as a decimal, then %) |
This formula gives a close approximation to the true APR for instalment loans but is not exact; it overestimates slightly for longer loan terms. A full IRR iteration would require a loop and more compute time.
Rounding Technique
Line 130 uses the classic BASIC one-decimal rounding idiom:
LET R = INT(R * 1000 + .5) / 10
Multiplying by 1000 and dividing by 10 (net ×100) converts the decimal fraction to a percentage while simultaneously rounding to one decimal place. The +.5 before INT provides standard half-up rounding.
Input Echo Pattern
Each INPUT statement (lines 30/50/60/80) is immediately followed by a PRINT of the variable just entered (lines 31/51/71/91). On the ZX81 the cursor and input line disappear after INPUT returns, so reprinting the value confirms to the user what was accepted. This is a well-known ZX81 UX workaround.
Loop Control
The repeat-or-exit logic at lines 160–190 tests only for "N"; any input other than “N” (including accidental keypresses) will loop back and start a new calculation. A stricter test would also check for "Y" explicitly.
Notable Idioms and Observations
- The
REMon line 5 contains the program title in inverse video characters, a common cosmetic convention. - Lines 135 and 150 use blank
PRINTstatements to add vertical spacing around the result, improving readability on a small display. - The trailing spaces inside the string
"THE EFFECTIVE INTEREST RATE ON THIS LOAN IS "(note the double space before “THIS”) appear to be manual formatting to control where the numeric result lands on screen. - The program ends with
SAVEfollowed byLIST, which lists the program to screen after saving — a common development convenience. - No error trapping is present; entering zero for
BorN+1would cause a division-by-zero error.
Content
Source Code
5 REM %E%F%F%E%C%T%I%V%E% %I%N%T%E%R%E%S%T
10 PRINT
20 PRINT "ENTER PAYMENTS IN 1 YEAR"
30 INPUT P
31 PRINT P
40 PRINT "TOTAL NR OF PAYMENTS"
50 INPUT N
51 PRINT N
60 PRINT "ENTER AMT OF PAYMENT"
70 INPUT A
71 PRINT A
80 PRINT "HOW MUCH IS BORROWED?"
90 INPUT B
91 PRINT B
120 LET R=2*P*((N*A)-B)/(B*(N+1))
130 LET R=INT (R*1000+.5)/10
135 PRINT
140 PRINT "THE EFFECTIVE INTEREST RATE ON THIS LOAN IS ";R;" PCT"
150 PRINT
160 PRINT "ANOTHER CALCULATION? ENTER Y OR N"
170 INPUT C$
180 IF C$="N" THEN GOTO 200
190 GOTO 10
200 SAVE "1011%1"
210 LIST
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
