--- title: "Savings Projection" id: 57009 type: "computer_media" slug: "savings-projection" url: "http://localhost/computer_media/savings-projection/" markdown_url: "http://localhost/computer_media/savings-projection.md" published_at: "2024-10-02T07:33:31+00:00" modified_at: "2026-03-30T21:20:14+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/33_Sav.png" excerpt: "Enter a starting balance, interest rate, and time horizon to watch compound interest build year by year in this simple savings projection tool." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Finance" slug: "finance" taxonomy: "genre" url: "http://localhost/type/finance/" - name: "Home" slug: "home" taxonomy: "genre" url: "http://localhost/type/home/" media_contents: - id: 56732 title: "Timex Sinclair Public Domain Library Tape 1001" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1001/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/33_Sav.png" media_type_tags: "Finance, Home" --- # Savings Projection 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: 1. **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`/`NEXT` loop. 2. **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. 3. **Projection loop** (lines 120–165): iterates `Y` times, updating the accumulated interest in `Z` and 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 160` to 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, so `Z` retains its value from the previous projection. This will produce incorrect totals on any second or subsequent calculation. - **Incomplete FOR statement**: Line 165 reads `FOR` with 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 the `GOTO`, 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 | ## 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 ```