Loan Payment

This file is part of and Timex Sinclair Public Domain Library Tape 1001. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Finance

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

VariableDescription
PPrincipal (amount borrowed, in dollars)
IInterest rate — entered as annual %, converted to monthly decimal
NNumber of monthly payments
MCalculated 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.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10001 – 10050.

Related Products

Related Articles

Related Content

Image Gallery

Loan Payment

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 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top