10
20
30
40 :
50
60 :
70 VDU26,12
80 PRINT "Mortgage Repayments Calculator"
90 PRINT "=============================="'
100 ON ERROR REPORT:IF ERR<>17:END
110 REPEAT
120 PRINT'"1: Loan table"'"2: Fixed repayment table"'"0: Exit ";
130 REPEATA$=GET$:UNTILINSTR("012",A$):PRINT
140 IFA$="1":PROCLoanTable
150 IFA$="2":PROCFixedRepaymentTable
160 UNTILA$="0"
170 END
180 :
190 :
200 :
210 :
220
230
240 DEFPROCFixedRepaymentTable
250 INPUT "Loan amount: "loan
260 INPUT "Base APR: "apr
270 INPUT "Initial monthly repayment: "repayment
280 INPUT "Annual percentage increment: "increment
290 CLS
300 PRINT" Monthly Interest Amount"
310 PRINT"Year Payments Charged Outstanding"
320 PRINT" at year end"
330 :
340
350 :
360 year=0 :
370 REPEAT
380 PRINT FNd(year+1,3);FNr(repayment,8,2);
390 loan0=loan :
400 FOR month=1 TO 12 :
410 interest=(loan0*((1+apr/100)/12))/12
420 loan=loan+interest :
430 loan=loan-repayment :
440 NEXT
450 PRINT FNr(loan-loan0+12*repayment,8,2); :
460 PRINT FNr(loan,8,2) :
470 year=year+1 :
480 repayment=repayment*(1+increment/100) :
490 UNTIL loan<0 :
500 ENDPROC
510 :
520 :
530 :
540 :
550
560
570 DEFPROCLoanTable
580 INPUT "Loan amount: "loan
590 INPUT "Base APR: "apr
600 inc0=0:inc1=2:incs=0.25:yr0=17:yr1=2
610 CLS
620 PRINTSPC6"Loan: "loan;SPC6"APR: ";apr;"%"'
630 PRINTSPC6"Initial monthly payment with increment"
640 PRINT"Term";
650 FOR increment=inc0 TO inc1 STEP incs
660 PRINT FNr(increment,5,2)"%";
670 NEXT:PRINT
680 FOR years=yr0 TO yr1 STEP -1:PRINT FNd(years,3);
690 FOR increment=inc0 TO inc1 STEP incs
700 payment=FNloan_payment(loan,apr,years,increment)
710 PRINT FNr(payment,6,2);
720 NEXT increment
730 PRINT
740 NEXT years
750 ENDPROC
760 :
770 :
780
790
800
810
820
830
840
850
860 :
870 DEFFNloan_payment(loan,apr,years,inc)
880 LOCAL payment,term,step,dir,newdir
890 payment=loan DIV (years*8) :
900 step=payment DIV 2 :
910 :
920 REPEAT :
930 payment=payment+step :
940 term=FNloan_term(loan,apr,payment,inc) :
950 UNTIL term<years :
960 :
970 dir=1 :
980 REPEAT
990 payment=payment+step*dir :
1000 term=FNloan_term(loan,apr,payment,inc) :
1010 IF term>years THEN newdir=1 ELSE newdir=-1
1020 IF newdir<>dir THEN step=step/2 :
1030 dir=newdir
1040 UNTIL term=years
1050 :
1060
1070 :
1080 =payment
1090 :
1100 :
1110 :
1120 :
1130
1140
1150
1160
1170
1180
1190
1200
1210 :
1220 DEFFNloan_term(loan,apr,repayment,increment)
1230 LOCAL year
1240 year=0 :
1250 REPEAT
1260 FOR month=1 TO 12 :
1270 loan=loan*((1+apr/100)^(1/12)) :
1280
1290 loan=loan-repayment :
1300 NEXT
1310 year=year+1 :
1320 repayment=repayment*(1+increment/100) :
1330 UNTIL loan<0 :
1340 =year
1350 :
1360 :
1370
1380
1390 DEFFNr(A,I%,D%):=FNd(INTA,I%)+"."+RIGHT$(STR$INT(A*10^D%),D%)
1400 DEFFNd(A%,N%)=RIGHT$(" "+STR$A%,N%)
1410 :
1420