This program calculates how many years it takes for a deposit to grow by a given multiplication factor at a specified annual interest rate. The user inputs an interest rate (as a percentage) and a target growth factor, and the program iterates year by year using compound interest via the exponentiation operator (`**`), counting periods until the accumulated amount exceeds the factor. After displaying the result, it pauses briefly and then reruns automatically. The program uses a simple iterative loop rather than the direct logarithmic formula, recalculating the full power `I**B` on each iteration rather than incrementally multiplying.
Program Analysis
Program Structure
The program is organized into three logical phases:
- Input phase (lines 10–45): Prompts the user for an annual interest rate and a growth factor, echoing each entry with a
PRINTstatement after input. - Computation loop (lines 50–130): Converts the interest rate to a multiplier, then iterates year-by-year counting until the compounded amount exceeds the target factor.
- Output and restart (lines 200–240, 9999): Displays results, pauses, clears the screen, and reruns automatically.
Algorithm
Line 50 transforms the percentage rate I into a compound interest multiplier: I = 1 + (I / 100). The loop then evaluates A = I ** B at each year B, incrementing B until A exceeds the target factor F. This is a brute-force approach — rather than computing B = LOG(F) / LOG(I) directly, it recalculates the full power from scratch on every iteration. For typical interest rates and modest growth factors the loop terminates quickly, so performance is not a practical issue.
Key BASIC Idioms
PRINT ,,andPRINT ,,,,— use comma-separated print positions to indent output across tab stops, a common layout technique.- Echo printing after
INPUT(lines 25 and 45) — restates the user’s entry, useful on systems where the input value may scroll or be unclear. PAUSE 40000— a long pause (approximately 11 minutes on a 50 Hz machine) effectively waits for user acknowledgement before continuing; combined with the subsequentRUN, it acts as a soft “press any key to restart.”RUNat line 240 (and line 9999) restarts the program completely, clearing all variables, creating a continuous-use kiosk loop.
Notable Techniques and Anomalies
- The exponentiation operator
**is used rather than^, indicating this is an early or non-Spectrum BASIC dialect. - Variables
AandBare explicitly initialised to zero at lines 60–70, which is redundant after a freshRUNbut would matter if execution ever reached line 60 without a full restart — defensive practice. - Line 9998 is a
SAVEcommand with the filenameDEPOSIT MULTIPLIE%R, where%Rrepresents an inverse-video letter R, serving as an auto-run flag embedded in the filename. - Line 9999 contains a second
RUN, which ensures that if the program is loaded without auto-run it still starts immediately. - The output at line 200 prints
A, the first value ofAthat exceedsF, meaning it reports the compounded amount one year after the target is first surpassed rather than the threshold crossing year itself — a minor off-by-one in the display ofA, thoughBcorrectly reflects the number of years elapsed.
Variable Summary
| Variable | Role |
|---|---|
I | Input interest rate (%), later overwritten with the multiplier 1 + I/100 |
F | Target growth factor supplied by the user |
B | Year counter (loop variable) |
A | Computed compounded amount I ** B at each iteration |
Content
Source Code
10 PRINT ,,"WHAT IS THE INTEREST RATE PER YEAR? ";
20 INPUT I
25 PRINT I
30 PRINT "WHAT IS THE INCREASE FACTOR? ";
40 INPUT F
45 PRINT F
50 LET I=1+(I/100)
60 LET A=0
70 LET B=0
100 LET A=I**B
110 IF A>F THEN GOTO 200
120 LET B=B+1
130 GOTO 100
200 PRINT ,,,,"THE AMOUNT WOULD BE ";A
210 PRINT "ITS SIZE IN ";B;" YEARS"
220 PAUSE 40000
230 CLS
240 RUN
9998 SAVE "DEPOSIT MULTIPLIE%R"
9999 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
