Loan Compare

Developer(s): John Colonna
Date: 1986
Type: Program
Platform(s): TS 2068
Tags: Finance

This program calculates monthly loan payments using the standard amortization formula: monthly payment = principal × monthly_rate / (1 − (1 + monthly_rate)^−n). It accepts a loan amount, number of monthly payments, and annual interest rate as inputs, then displays both the monthly and total payment figures. Display formatting uses FOR/NEXT loops at lines 500 and 600 to draw decorative separator bars of inverse-video dollar signs and dashes across the full 32-column width. Line 9999 provides a save/verify routine that stores the program with an auto-run entry point at line 1.


Program Analysis

Program Structure

The program is organized into a linear main flow (lines 5–185) with two reusable display subroutines (lines 500–650) and a standalone save routine at line 9999. Control flow is straightforward: gather three inputs, compute the monthly payment, display results, then offer a copy/repeat menu.

Line RangePurpose
5REM header with author and version
10–20Initialization: CLS, BORDER, variable reset, opening banner
25–110Input section: loan amount, number of payments, annual interest rate
115–160Calculation and results display
165–185Post-result menu: print copy or restart
500–550Subroutine: 32-character inverse-video “$” separator bar
600–650Subroutine: 32-character “-” separator bar
9999Save/verify utility

Amortization Formula

The core calculation occupies lines 110–125. Line 110 converts the user-supplied annual percentage rate to a monthly decimal rate: i = (0.01 * i) / 12. Line 120 applies the standard amortization formula:

p = t * i / (1 - 1 / (1 + i) ^ n)

where t is the principal, i is the monthly rate, and n is the number of payments. Line 125 rounds the result to the nearest cent using the classic idiom INT(100 * p + 0.5) / 100.

Display Techniques

Two separator-bar subroutines use FOR/NEXT loops running exactly 32 iterations to fill the screen width. The subroutine at line 500 prints inverse-video "$" characters to create a highlighted border effect, while the one at line 600 prints plain "-" dashes. Each input value is echoed back on the screen using INVERSE 1 with TAB positioning (lines 45, 75, 105), giving a form-entry feel.

Input and Menu Handling

Line 165 uses a compound INPUT statement with embedded INVERSE attributes to display a styled prompt asking the user to choose between printing a copy ("1") or running again ("2"). Line 170 handles the LPRINT option, reconstructing the original annual rate from the stored monthly decimal by computing i * 1200 for display. Line 175 restarts the program by jumping to line 1 (which does not exist), causing the program to terminate — this is a known idiom for a clean restart that falls through to the end. Line 180 loops back to the menu if neither valid choice is entered.

Notable Techniques and Anomalies

  • Line 15 initializes p=0 explicitly, which is unnecessary since BASIC variables default to zero, but serves as self-documentation.
  • The GO TO 1 at line 175 targets a non-existent line; execution stops rather than truly restarting. A correct restart would target line 10 or use RUN.
  • The LPRINT line (170) is very long, combining column headers and computed values in a single statement, relying on the printer’s 32-column (or wider) carriage width for readability.
  • Line 9999 is intentionally isolated and only reached manually, providing a convenient save-and-verify workflow without interfering with normal program execution.
  • The variable l is reused as the loop counter in both separator subroutines, which is safe since the subroutines are never called from within each other.

Content

Appears On

Library tape from the Sinclair Computer Users Society (SINCUS).

Related Products

Related Articles

Related Content

Image Gallery

Loan Compare

Source Code

    5 REM loancompar - J. Colonna        Version 1.1  Rev. 7-86
   10 CLS : BORDER 6
   15 LET p=0
   20 GO SUB 500
   25 PRINT : PRINT 
   30 PRINT "  Enter the amount of the loan"
   35 PRINT 
   40 INPUT t
   45 PRINT TAB 14; INVERSE 1;t
   50 GO SUB 600
   55 PRINT 
   60 PRINT "Enter number of monthly payments"
   65 PRINT 
   70 INPUT n
   75 PRINT TAB 15; INVERSE 1;n
   80 GO SUB 600
   85 PRINT 
   90 PRINT " Enter the annual interest rate"
   95 PRINT "     (For Example - 12.5)"
  100 INPUT i
  105 PRINT TAB 13; INVERSE 1;i;" %"
  110 LET i=(0.01*i)/12
  115 PRINT 
  120 LET p=t*i/(1-1/(1+i)^n)
  125 LET p=INT (100*p+.5)/100
  130 GO SUB 500
  135 PRINT : PRINT 
  140 PRINT "Monthly payment will be: $";p
  145 PRINT 
  150 PRINT "Total payment will be: $";p*n
  155 PRINT 
  160 GO SUB 500
  165 INPUT INVERSE 1;"COPY(1) or AGAIN(2)?"; INVERSE 0;" ";a$
  170 IF a$="1" THEN LPRINT ; INVERSE 1;" AMT.  NUMBER OF  INT.  MONTHLY  LOAN  PAYMENTS   RATE  PAYMENT "; INVERSE 0;"$";t;"     ";n;"       ";i*1200;"%   $";p: LPRINT 
  175 IF a$="2" THEN GO TO 1
  180 GO TO 165
  185 STOP 
  500 FOR l=1 TO 32: PRINT INVERSE 1;"$";: NEXT l
  550 RETURN 
  600 FOR l=1 TO 32: PRINT "-";: NEXT l
  650 RETURN 
 9999 CLEAR : CLS : SAVE "loancompar" LINE 1: BEEP 1,25: PRINT "loancompar SAVED": VERIFY "": PRINT "Program VERIFIED": BEEP .5,32: BEEP .5,32

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

Scroll to Top