A loan calculator. A double-ruled box drawn with PLOT and DRAW holds four fields: loan amount, annual interest rate, number of payments and monthly payment. You are asked for each in turn and enter 0 to skip one, and from any three the program works out the fourth. Once the amount, rate and number of payments are filled in, it goes straight to the monthly payment. The result is printed in its field, and pressing C copies the screen to the printer. Any other key starts a new calculation.
The program carries no author credit.
Program Analysis
Calculations
- Monthly payment (lines 270–310): the annuity formula
L*i/(1-(1+i)^-n), with the monthly rateiequal to the annual percentage divided by 1200. The result is rounded to the cent by adding 0.005 beforeFN f. - Loan amount (lines 390–430): the same formula solved for the principal.
- Interest rate (lines 440–520): starts from 1% a month and makes 80 passes of
i=(i+p*(1-(1+i)^-n)/L)/2, averaging each estimate with the last. The result is cut to hundredths of a percent. A payment smaller thanL/ngives “Payment is too small!”. - Number of payments (lines 320–380): a stepping search from 100 payments with a step
dnof 128. It gives up with “Payment is too small!” above 1000 payments, or if the answer is over 480. FN f(x)=INT (x*100)/100cuts entries to whole cents. It truncates rather than rounds.
Notable Techniques
GO TO (100+10*c)picks the input line for each field.- A user-defined function,
DEF FN f, handles the cents arithmetic. PRINT AT PI,5usesPIfor the row number 3.- The prompt offers a printer copy of the finished form with
COPY.
Potential Issues
- The number of payments can never be found. Line 360 does
LET n=n-dn: LET n=n+dn/4: LET n=n+dn, which addsdn/4tonbut never makes the step smaller.dnstays at 128, sodn>=0.5is always true and the search keeps raisingnuntil it passes 1000. Every payment, however large, then gets “Payment is too small!”. For example, $10000 at 8% with a $202.76 payment should give 60. - The blanking strings printed before each result are shorter than the dashed placeholders, so the ends of the dashes stay on screen beside the figures (for example “8 -%Annual Interest”).
This program came from an Oliger (JLO SAFE) disk in the SNUG library set and was converted for tape. The Oliger slash was removed from the SAVE in line 570. It was tested in ZEsarUX on a stock TS2068: a $10000 loan at 8% over 60 payments gave the correct monthly payment of $202.76.
Source Code
10 BRIGHT 0: PAPER 1: BORDER 1: INK 7: CLS : GO SUB 260: DEF FN f(x)=INT (x*100)/100
20 PRINT OVER 1;'" $------.-- Loan amount"''" --.--%Annual Interest"''" ----- Number of Payments"''" $----.-- Monthly Payment"
30 PRINT AT 17,1;" Input Data for any 3 Items."''" Press""ENTER""when done."''" Input 0 to skip an item."
40 LET L=0: LET I=L: LET N=L: LET P=L: FOR c=1 TO 4
50 IF c=1 THEN PRINT AT 5,5; OVER 1;" "
60 IF c=2 THEN PRINT AT 7,4; OVER 1;" "
70 IF c=3 THEN PRINT AT 9,4; OVER 1;" "
80 IF c=4 THEN PRINT AT 11,5; OVER 1;" "
90 GO TO (100+10*c)
100 REM c starts here
110 INPUT "Loan Amount: ";L: LET L=FN f(l): LET loan=L: GO SUB 240: GO TO 150
120 INPUT "Interest Rate:";i: LET i=FN f(i): LET ir=i: GO SUB 230: GO TO 150
130 INPUT "Number of Payments:";n: LET n=INT (n): GO SUB 220: GO TO 150
140 INPUT "Monthly Payment:";p: LET p=FN f(p): GO SUB 250
150 IF L<>0 AND i<>0 AND n<>0 THEN GO TO 170
160 NEXT c
170 IF p=0 AND L<>0 AND i<>0 AND n<>0 THEN GO TO 270
180 IF L=0 AND p<>0 AND i<>0 AND n<>0 THEN GO TO 390
190 IF i=0 AND L<>0 AND p<>0 AND n<>0 THEN GO TO 440
200 IF n=0 AND L<>0 AND p<>0 AND i<>0 THEN GO TO 320
210 GO TO 20
220 PRINT AT 9,4;" ": PRINT AT 9,4;n: RETURN
230 LET I$=STR$ I: PRINT AT 7,4;" ";AT 7,4;I$: RETURN
240 LET L$=STR$ L: PRINT AT 5,5;" ";AT 5,5;L$: RETURN
250 LET P$=STR$ P: PRINT AT 11,5;" ";AT 11,5;P$: RETURN
260 PLOT 30,155: DRAW 200,0: DRAW 0,-80: DRAW -200,0: DRAW 0,80: PLOT 28,157: DRAW 204,0: DRAW 0,-84: DRAW -204,0: DRAW 0,84: PRINT AT PI,5;"Loan Terms": RETURN
270 LET i=i/1200
280 LET p=FN f((L*i)/(1-(1+i)^(-n))+0.005)
290 LET p=FN f(p)
300 GO SUB 250
310 GO TO 530
320 LET i=i/1200: LET n=100: LET dn=128
330 LET P1=FN f((L*I)/(1-(1+I)^(-N))+0.005)
340 IF N>1000 THEN GO TO 380
350 IF p1>p THEN LET n=n+dn: GO TO 330
360 LET n=n-dn: LET n=n+dn/4: LET n=n+dn: IF dn>=0.5 THEN GO TO 330
370 LET n=INT (n+.8): IF n<=480 THEN GO SUB 220: GO TO 530
380 PRINT AT 9,4;"Payment is too small! ": BEEP .1,1: PAUSE 120: LET i=ir: LET c=4: PRINT AT 17,12;" ": LET n=0: GO SUB 550: GO TO 50
390 LET i=i/1200
400 LET L=p*(1-(1+i)^(-n))/i
410 LET L=FN f(L)
420 GO SUB 240
430 GO TO 530
440 LET i=0.010
450 FOR J=1 TO 80
460 LET I2=p*(1-(1+i)^(-n))/L
470 LET i=(i+I2)/2
480 NEXT J
490 LET i=INT (i*120000)/100
500 GO SUB 230
510 LET i=i/1200
520 IF p<(L/n) THEN PRINT AT 9,4;"Payment is too small! ": BEEP .1,1: PAUSE 120: LET i=ir: LET c=4: PRINT AT 17,12;" ": LET i=0: GO SUB 550: GO TO 50
530 PRINT AT 17,0;"press ""C"" to COPY, any other keyto continue.",,,,,,,,: PAUSE 0: LET i$=INKEY$: IF i$="C" OR i$="c" THEN COPY : GO TO 530
540 GO TO 10
550 GO SUB 260
560 PRINT AT 5,4;"$";loan,"Loan Amount";AT 7,4;ir;TAB 10;"%Annual Interest";AT 9,4;n;TAB 10;"Number of Payments";AT 11,4;"$";p;TAB 13;"Monthly Payment": RETURN
570 SAVE /"LOAN" LINE 10Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

