--- title: "Loan Payment" id: 57003 type: "computer_media" slug: "loan-payment" url: "http://localhost/computer_media/loan-payment/" markdown_url: "http://localhost/computer_media/loan-payment.md" published_at: "2024-10-02T07:23:24+00:00" modified_at: "2026-03-30T21:20:18+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/27_Loan.png" excerpt: "A compact loan amortisation calculator that applies the classic annuity formula, converts annual interest to monthly rate, and loops for repeated calculations with a keypress pause." 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/" 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/27_Loan.png" media_type_tags: "Finance" --- # Loan Payment This program calculates the fixed monthly payment required to amortise a loan, implementing the standard annuity formula M = P·i / (1 − (1+i)^−N). It accepts three inputs—principal borrowed, annual interest rate as a percentage, and number of monthly payments—then displays the resulting monthly payment amount. The annual interest rate is converted to a monthly rate by dividing by 1200 (lines 50). After displaying the result, the program waits for any keypress using a busy-loop on INKEY$ before cycling back to accept a new loan calculation. The SAVE at line 100 uses an inverse-video digit in the filename as an auto-run flag. *** ## Program Analysis ### Program Structure The program is a straightforward linear input-calculate-output loop with no subroutines. Control flow is minimal: after displaying the result, a busy-loop waits for a keypress, then `GOTO 20` restarts the input sequence. Line numbering is sparse and irregular, suggesting the program was edited after initial entry. 1. **Lines 1–4:** Title display using inverse-video characters via `PRINT`. 2. **Lines 15–65:** Initialisation and three `INPUT` statements collecting principal (`P`), annual interest rate (`I`), and number of payments (`N`). 3. **Line 50:** Interest rate conversion — annual percentage to monthly decimal. 4. **Line 70:** Core annuity formula evaluation. 5. **Lines 75–85:** Result display, blank line, keypress wait loop, then restart. 6. **Lines 100–200:** Utility lines: `SAVE` with auto-run flag, and a bare `RUN`. ### The Annuity Formula Line 70 computes the standard fixed-payment mortgage/loan formula: `LET M=P*I/(1-((1+I)**(-N)))` This implements M = P·i / (1 − (1+i)−N), where `P` is the principal, `I` is the monthly interest rate (after conversion), and `N` is the total number of monthly payments. The exponentiation operator `**` is used for raising to a negative power, which is valid ZX81/TS1000 BASIC. ### Interest Rate Conversion Line 50 performs `LET I=(0.01*I)/12`, which converts an annual percentage rate entered by the user (e.g. 12 for 12%) into a monthly decimal rate (0.01). This is mathematically correct for a simple (non-compounded) annual-to-monthly conversion and is the standard approach used in loan amortisation tables. ### Key BASIC Idioms - **Input echo:** After each `INPUT`, the entered value is re-printed on the next line (lines 30, 45, 65). This is a common ZX81 idiom to confirm the value visually, since the system replaces the input prompt line after entry. - **Keypress wait loop:**`IF INKEY$="" THEN GOTO 80` at line 80 is the standard busy-loop technique for waiting until any key is pressed before continuing. - **Variable initialisation:**`LET M=0` at line 15 pre-initialises the result variable before the loop, though it is overwritten unconditionally on every pass and is not strictly necessary. ### Variable Summary | Variable | Description | | --- | --- | | `P` | Principal (amount borrowed, in dollars) | | `I` | Interest rate — entered as annual %, converted to monthly decimal | | `N` | Number of monthly payments | | `M` | Calculated monthly payment amount | ### Potential Anomalies - **Zero interest rate:** If the user enters `I=0`, line 70 will cause a division-by-zero error, as `I` becomes `0` and the formula collapses. No error guard is present. - **Zero payments:** Entering `N=0` will similarly produce a division-by-zero, since `(1+I)**0 = 1`, making the denominator zero. - **Line 15 placement:**`LET M=0` is only executed once at program start, not on each loop iteration (the loop returns to line 20). This is harmless since `M` is always recalculated at line 70, but the initialisation serves no practical purpose within the loop. ## Source Code ``` 1 REM *MONTHLY LOAN PAYMENT* 3 PRINT "%M%O%N%T%H%L%Y% %L%O%A%N% %P%A%Y%M%E%N%T" 4 PRINT 15 LET M=0 20 PRINT "AMT BORROWED = $"; 25 INPUT P 30 PRINT P 35 PRINT "ANNUAL INTEREST = "; 40 INPUT I 45 PRINT I 50 LET I=(0.01*I)/12 55 PRINT "NO. OF PAYMENTS = "; 60 INPUT N 65 PRINT N 70 LET M=P*I/(1-((1+I)**(-N))) 75 PRINT "MO. PAYMENT = $ ";M 77 PRINT 80 IF INKEY$="" THEN GOTO 80 85 GOTO 20 100 SAVE "1002%7" 200 RUN ```