This program calculates a savings projection by computing compound interest year by year over a user-specified number of years. The user inputs a present balance, an annual interest rate (as a percentage), and a number of years; the program then prints each year’s running total. The accumulator variable Z tracks cumulative interest separately from the principal B, with the formula Z = Z + I*(Z+B)/100 applied each iteration. After displaying results, the program waits for a keypress and loops back to restart, allowing fresh calculations without re-running the program.
Program Analysis
Program Structure
The program is organised into three logical phases that cycle continuously:
- Initialisation and header (lines 10–19): clears the screen, prints a title, and draws a row of 18 asterisks as a separator using a
FOR/NEXTloop. - Input collection (lines 20–110): prompts for and reads the present balance (
B), interest rate (I), and number of years (Y), echoing each value back to the screen. - Projection loop (lines 120–165): iterates
Ytimes, updating the accumulated interest inZand printing the year number alongside the total balance.
Interest Calculation
The core formula at line 130 is:
LET Z=Z+I*(Z+B)/100
Here B is the original principal (never modified) and Z holds the cumulative interest earned to date. Each year, I percent is applied to the current total balance (Z+B) and added to Z. This correctly models annual compound interest without altering the original principal variable. Line 140 then prints the year index L and the total balance Z+B in two tab-separated columns.
Key BASIC Idioms
- Keypress wait: Line 160 uses the classic busy-wait idiom
IF INKEY$="" THEN GOTO 160to pause until any key is pressed before looping. - Separator banner: Lines 16–18 build the asterisk border programmatically rather than embedding a literal string, saving a few bytes and making the width easy to change.
- Continuous loop: Line 170 jumps back to line 15 (rather than line 10), redrawing the header and banner but skipping the
CLS— a minor quirk that means subsequent runs do not clear the screen before reprinting the title.
Notable Techniques
The accumulator design (Z for interest, B for principal) is a neat separation of concerns: the original balance is always available for the compound calculation without needing to re-enter it. Initialising Z=0 at line 20 ensures the accumulator is reset correctly on the first pass, but because line 170 returns to line 15 rather than line 20, Z is not reset on subsequent calculations — see the anomaly note below.
Bugs and Anomalies
- Z not reset on repeat: Line 20 (
LET Z=0) is only reached on the very first run. When the program loops back via line 170 to line 15, it skips line 20, soZretains its value from the previous projection. This will produce incorrect totals on any second or subsequent calculation. - Incomplete FOR statement: Line 165 reads
FORwith no variable, range, or body. This appears to be a corrupt or truncated line — likely a remnant or editing accident. On execution it will cause a syntax error before it is ever reached (it sits between the keypress wait and theGOTO, so control flow skips it, but it remains in the listing as dead, malformed code. - CLS skipped on repeat: As noted, the loop target is line 15, not line 10, so the screen is never cleared between successive projections, causing output to accumulate.
Variable Summary
| Variable | Purpose |
|---|---|
B | Initial (present) balance entered by user |
I | Annual interest rate (percent) |
Y | Number of years to project |
Z | Accumulated interest (running total above principal) |
L | Loop counter / year index |
G | Loop counter for asterisk separator |
Content
Source Code
5 REM %S%A%V%I%N%G%S
10 CLS
15 PRINT "SAVINGS PROJECTION"
16 FOR G=1 TO 18
17 PRINT "*";
18 NEXT G
19 PRINT
20 LET Z=0
30 PRINT "PRESENT BALANCE: ";
40 INPUT B
50 PRINT B
60 PRINT "INTEREST RATE: ";
70 INPUT I
80 PRINT I
90 PRINT "NUMBER OF YEARS: ";
100 INPUT Y
110 PRINT Y
120 FOR L=1 TO Y
130 LET Z=Z+I*(Z+B)/100
140 PRINT L,Z+B
150 NEXT L
159 PRINT "FOR MORE,PRESS ANY KEY"
160 IF INKEY$="" THEN GOTO 160
165 FOR
170 GOTO 15
200 SAVE "1003%3"
300 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
