This program calculates compound interest on a savings account with regular monthly deposits. The user enters an initial lump sum, a monthly deposit amount, an annual interest rate, and the investment duration in years. The loop at lines 190–220 iterates month by month, applying the compounded monthly rate to the running balance plus each deposit. At completion, it displays the total value, total amount invested, and the net interest earned. The program uses the ZX81’s FAST mode (line 150) to speed up the iterative calculation loop.
Program Analysis
Program Structure
The program is divided into three clear phases: data entry (lines 10–140), calculation (lines 150–220), and results display (lines 230–260). Input values are echoed back to the screen using PRINT AT statements, placing them at fixed column 20 on their respective rows to form a simple summary panel alongside the prompts.
Calculation Method
The interest calculation loop (lines 190–220) uses a counter variable C compared against the total number of months T (converted at line 160 by multiplying the user’s years value by 12). Each iteration adds the monthly deposit B to the current balance A, then multiplies by the monthly interest factor I, which is precomputed at line 170 as I/100/12+1. This correctly converts an annual percentage rate to a monthly multiplier and folds the “+1” in so the multiplication applies both principal growth and interest in one step.
Variable Usage
| Variable | Role |
|---|---|
A | Running balance (initially the lump sum, updated each month) |
B | Monthly deposit amount |
I | Monthly interest multiplier (reused from annual rate input) |
T | Duration in years (input), then overwritten with total months |
C | Loop counter (months elapsed) |
D | Snapshot of the initial amount, saved before A is modified |
Notable Techniques
- FAST mode: Line 150 invokes
FASTbefore the loop begins, suppressing the display driver to accelerate the iterative calculation — important when the loop may run hundreds of iterations for multi-year periods. - Variable reuse: Both
AandTare repurposed after input, which saves memory but requiresDto preserve the original initial amount for the final output calculations at lines 240–250. - Results display:
TAB 20is used in the output section to align the computed values consistently, mirroring the column-20 alignment used during data entry.
Bugs and Anomalies
- Typo in prompt: Line 20 prints
"INITIAL AMMOUNT"— “AMMOUNT” is misspelled; it should be “AMOUNT”. - FAST mode not cleared: The program enters
FASTat line 150 but never issues aSLOWcommand. Output at lines 230–250 is therefore rendered in FAST mode, which on a ZX81 causes the display to blank during calculations and may produce a flickering or absent display for the results. - Total investment formula: Lines 240–250 compute total invested as
T*B+D, using the already-convertedT(months). This is correct sinceBis a monthly deposit andTnow holds the month count, but the reuse ofTmakes the logic easy to misread. - Lines 270–280: The
SAVEandRUNat lines 270–280 are utility lines for tape storage and restarting the program; they are not reached during normal execution.
Content
Source Code
10 PRINT "INTEREST"
20 PRINT "INITIAL AMMOUNT"
30 INPUT A
40 PRINT AT 0,20;A
50 PRINT "MONTHLY DEPOSIT"
60 INPUT B
70 PRINT AT 1,20;B
80 PRINT "ANNUAL INTEREST"
90 INPUT I
100 PRINT AT 2,20;I
110 LET C=0
120 PRINT "LENGTH OF TIME"
130 INPUT T
140 PRINT AT 3,20;T
150 FAST
160 LET T=T*12
170 LET I=I/100/12+1
180 LET D=A
190 IF C=T THEN GOTO 230
200 LET A=(A+B)*I
210 LET C=C+1
220 GOTO 190
230 PRINT "TOTAL VALUE";TAB 20;A
240 PRINT "TOTAL INVESTMENT";TAB 20;T*B+D
250 PRINT "TOTAL INTEREST";TAB 20;A-(T*B+D)
260 STOP
270 SAVE "1016%2"
280 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
