1 COMMON A, AL, B, BASEONLY, C, C$, C1, CAT$, CC, CKT$, D, D$, DD, DIA, DIMN$, DMS, E, EO, EX$, F, F$, FD, FF, FQ, FRQ, G$, GO$, I, I$, L, LATLONG, LD, LL, LN, LS, LW, LX, MAX, MENU, MIN, MX, N, NN, NT, OV, P, PI, PROG$, Q, QQ, QU, R, RA, RC, T, T$, U, U$, UH, UL$, V$, VC, W, WHIP, WIRD, WW, X, X$, X1, XS, Z$, ZP, ZS
5 'OMMON EX$,PROG$
10 'MORTGAG : 31 OCT 87 - rev. 25 MAY 2010
20 CLS:KEY OFF
30 
40 IF EX$=""THEN EX$="EXIT"
50 IF PROG$=""THEN GO$=EX$ ELSE GO$=PROG$
60 DEFDBL A
70 CLS:COLOR 7,0
80 U=1:DIM PN(50),EP(50)
90 UL$=STRING$(80,205)
100 A$="##,###,###.##"
110 B$="#############"
120 DATA 1,JAN,2,FEB,3,MAR,4,APR,5,MAY,6,JUN
130 DATA 7,JUL,8,AUG,9,SEP,10,OCT,11,NOV,12,DEC
140 DIM W$(12,2)
150 FOR Z=1 TO 12:FOR Y=1 TO 2:READ W$(Z,Y):NEXT Y:NEXT Z:RESTORE
160 GOTO 270
170 '
180 U=M+T
190 IF INT(U)>12 THEN U=U-12+9.999999E-03:GOTO 190
200 FOR Z=1 TO 12:IF VAL (W$(Z,1))<>INT(U) THEN 250
210  W=CINT((U-INT(U))*100):IF W>99 THEN W=100-W
220  W$=W$(Z,2)+STR$(W)
230  IF LEN(W$)=5 THEN W$=LEFT$(W$,4)+"0"+RIGHT$(W$,1)
240  RETURN
250 NEXT Z
260 '
270 '.....start
280 FLAG1=0:A=0:I=0:C=0:P=0:N=0:M=0:D=0:Y=0:YY=0:J=0:B=0:R=0:T=0
290 DAT$=""
300 CLS
310 PRINT TAB(30);"MORTGAGE CALCULATOR"
320 PRINT UL$;
330 GOSUB 2380
340 PRINT UL$;
350 PRINT TAB(28);"Press number in ( ) to:"
360 COLOR 7,0
370 PRINT UL$;
380 PRINT TAB(31);"(1)  Run program"
390 PRINT TAB(31);"(0)  EXIT"
400 Z$=INKEY$
410 IF Z$="1"THEN CLS:GOTO 530
420 IF Z$="0"THEN CLS:CHAIN GO$
430 ON ERROR GOTO 460
440 GOTO 400
450 '
460 '.....errortrap
470 VIEW PRINT:CLS:PRINT "Error";ERR;"in line";ERL:END
480 '
490 '.....blank input entry box
500 FOR ZZ=3 TO CSRLIN-1:COLOR 7,0
510 LOCATE ZZ,41:PRINT STRING$(40,32);:NEXT ZZ:RETURN
520 '
530 '.....heading
540 LOCATE 7:COLOR 7,0:PRINT UL$      'bottom margin of heading
550 LOCATE 1,41:PRINT "MORTGAGE PAYMENT SCHEDULE"
560 LOCATE 2,41:PRINT STRING$(40,205);
570 '.....inputs
580 COLOR 0,7
590 LOCATE 3,41:COLOR 0,7:INPUT " ENTER: Amount of mortgage";A
600 GOSUB 490
610 LOCATE 2,1:COLOR 7,0:PRINT "Amount of mortgage....$";USING A$;A
620 LOCATE 3,41:COLOR 0,7:INPUT " ENTER: Interest rate (%)..... ";I
630 LOCATE 4,41:COLOR 0,7:INPUT " Compounded ? times a year.... ";C
640 GOSUB 490
650 IF C>12 THEN 630
660 IF C=0 THEN C=2
670 LOCATE 3,1:COLOR 7,0:PRINT "Interest rate......... ";USING A$;I;:PRINT "%"
680 '
690 GOSUB 490:COLOR 0,7
700 LOCATE 3,41:PRINT " Press number in ( ) to enter:"
710 LOCATE 4,41:PRINT "   (1) Monthly payment        "
720 IF FLAG1 THEN FLAG1=0:GOTO 750
730 LOCATE 5,41:PRINT "        - or -                "
740 LOCATE 6,41:PRINT "   (2) Amortization (years)   "
750 Z$=INKEY$
760 IF Z$="1"THEN GOSUB 490:GOSUB 800:GOTO 950
770 IF Z$="2"THEN GOSUB 490:GOSUB 870:GOTO 950
780 GOTO 750
790 '
800 '.....monthly payment known
810 LOCATE 3,41:COLOR 0,7:INPUT " ENTER: Monthly payment.......$";P
820 FLAG1=1
830 COLOR 7,0
840 LOCATE 4,1:PRINT "Monthly payment.......$";USING A$;P
850 RETURN
860 '
870 '.....amortization years known
880 LOCATE 3,41:COLOR 0,7:INPUT " ENTER: Number of years....... ";Z
890 N=Z*12
900 GOSUB 920:GOTO 950
910 '
920 COLOR 7,0:LOCATE 5,1:PRINT "Amortization (years).. ";USING A$;Z
930 RETURN
940 '
950 GOSUB 490:IF DAT$<>""THEN 1180
960 '
970 '.....start date
980 D$="":Y=0:M$=""
990 LOCATE 3,41:COLOR 0,7:INPUT " ENTER: Start (mm-dd-yyyy)";DAT$
1000 COLOR 7,0
1010 D$=DAT$+"-"
1020 FOR Z=1 TO LEN(D$)
1030  M$=M$+MID$(D$,Z,1)
1040  IF MID$(D$,Z,1)="-" THEN Y=Y+1:D(Y)=VAL (M$):M$=""
1050 NEXT Z
1060 '
1070 M=D(1):D=D(2):Y=D(3)
1080 IF M<=12 AND D<=31 THEN 1130
1090 GOSUB 490:BEEP:PRINT "Invalid date - Press any key to continue"
1100 Z$=INKEY$:IF Z$=""THEN 1100
1110 GOTO 950
1120 '
1130 FOR Z=1 TO 12
1140 IF VAL (W$(Z,1))=M THEN M$=" "+W$(Z,2):GOTO 1170
1150 NEXT Z
1160 '
1170 Y$=STR$(Y):IF VAL(Y$)<10 THEN Y$=" 0"+RIGHT$(Y$,1)
1180 LOCATE 6,1:PRINT "Starting date......... ";USING "######";D;:PRINT M$;Y$
1190 GOSUB 490
1200 LOCATE 3,41:COLOR 0,7:PRINT " Extra Payments.........? (y/n) "
1210 COLOR 7,0
1220 Z$=INKEY$
1230 IF Z$="N"OR Z$="n"THEN GOSUB 490:GOTO 1330
1240 IF Z$="Y"OR Z$="y"THEN B=0:GOTO 1250 ELSE 1220
1250 J=J+1
1260 GOSUB 490:B=B+1
1270 LOCATE 3,41:COLOR 0,7:INPUT " ENTER: Extra payment month no.";PN(B)
1280 IF PN(B)=0 THEN B=B-1:GOSUB 490:GOTO 1330
1290 GOSUB 490
1300 LOCATE 3,41:COLOR 0,7:INPUT " ENTER: Extra payment Amount.. ";EP(B)
1310 GOTO 1250
1320 '
1330 DEFDBL R
1340 R=(1+(I/100)/C)^(C/12)-1
1350 IF P=0 THEN 1440
1360 IF P>(A*R) THEN 1500
1370 BEEP:LOCATE 4,1:COLOR 0,7
1380 PRINT " Min.monthly payment is $";USING "####,###.##";A*R+9.999999E-03:COLOR 7,0
1390 GOSUB 690
1400  FOR Z=1 TO 2
1410  LOCATE Z,41:PRINT STRING$(40,32)
1420  NEXT Z
1430 GOTO 1500
1440 X=(R+1)^N:P#=A*R*X/(X-1)
1450 P=(P#*100)
1460 IF P=INT(P)THEN P=INT(P) ELSE P=INT(P)+1
1470 P=P/100
1480 GOSUB 840:GOTO 1520
1490 '
1500 N=LOG(P/(P-A*R))/LOG(1+R)  'number of months
1510 Z=N/12:GOSUB 920
1520 C$=""
1530 IF C=1 THEN C$=" annually"
1540 IF C=2 THEN C$=" semi-annually"
1550 IF C=4 THEN C$=" quarterly"
1560 IF C=6 THEN C$=" bi-monthly"
1570 IF C=12 THEN C$=" monthly"
1580 IF C$=""THEN C$=STR$(C)+" times per year"
1590 LOCATE 3,41:PRINT "Compounded";C$
1600 PMT=INT(N)                    'number of payments
1610 LOCATE 4,40:PRINT PMT;;"payments";
1620 LOCATE 6,41
1630 PRINT USING "Effective monthly rate... ####.#### %";R
1640 '
1650 '.....print tables
1660 VIEW PRINT 8 TO 24
1670 TRM=N
1680 COLOR 0,7:PRINT " Do you want to see a payment schedule?  (y/n) "
1690 COLOR 7,0
1700 Z$=INKEY$:IF Z$="n"THEN 270
1710 IF Z$="y"THEN 1720 ELSE 1700
1720 COLOR 7,0:PRINT "Press number in < > to select printout:";
1730 COLOR 0,7
1740 PRINT "  <1> Entire amortization period "
1750 PRINT "  <2> Renewal period only        "
1760 COLOR 7,0
1770 Z$=INKEY$:IF Z$="1"THEN 1840
1780 IF Z$="2"THEN 1790 ELSE 1770
1790 INPUT " ENTER: Renewal period (years) ";YRS
1800 TRM=YRS*12
1810 VIEW PRINT 1 TO 24
1820 LOCATE 4,40:PRINT TRM;;"payments    "
1830 LOCATE 5,41:PRINT "Term (years).......... ";YRS
1840 VIEW PRINT 8 TO 24:CLS
1850 PRINT TAB(4);"Payment No.";TAB(28);;"Date";TAB(38);;"Principal";
1860 PRINT TAB(52);;"Interest";TAB(66);;"Balance";
1870 VIEW PRINT 9 TO 24
1880 FOR Z=1 TO 12:IF VAL (W$(Z,1))=M THEN M$=" "+W$(Z,2):GOTO 1900
1890 NEXT Z
1900 Y$=STR$(Y)
1910 PRINT TAB(14);USING B$;D;:PRINT M$;Y$;
1920 PRINT TAB(60);USING A$;A
1930 IF M=12 THEN 2320
1940 '
1950 K=M+1:IF K>12 THEN Y=Y+1:K=1:BEEP:PRINT Y:STOP
1960 IF Y>50 THEN YR=1900 ELSE YR=2000
1970 VIEW PRINT:LOCATE 1,67:PRINT"for";YR+Y:VIEW PRINT 9 TO 24:LOCATE 10
1980 S=0:T=0:GOTO 2050
1990 '
2000 '.....print loop
2010 S=0:T=0
2020 VIEW PRINT:LOCATE 1,67:PRINT "for";X+1:VIEW PRINT 9 TO 24:LOCATE 9
2030 '
2040 '.....calculate & print one line
2050 FOR J=K TO 12:Q=P
2060 FOR F=1 TO B:IF PN(F)<>U THEN 2080
2070 Q=EP(F)+P:GOTO 2090
2080 NEXT F
2090 G=A*R:G=INT(G*100+5.000000E-01)/100
2100 H=Q-G:AA=A:A=A-H:IF A>9.999999E-03 THEN 2120
2110 H=H+A:Q=H+G:A=0
2120 FOR Z=1 TO 12:IF VAL (W$(Z,1))=J THEN M$=" "+W$(Z,2):GOTO 2150
2130 NEXT Z
2140 Y$=STR$(Y)
2150 PRINT STRING$(80,32);:LOCATE CSRLIN-1
2160 IF U<TRM THEN 2180
2170 PRINT "LAST PAYMENT ";USING "$#,###.##";H+G;:B$="####":GOTO 2190
2180 PRINT USING B$;U;
2190 PRINT USING B$;D;:PRINT M$;Y$;
2200 PRINT USING A$;H;G;A
2210 S=S+G:T=T+H:U=U+1:IF A=0 OR U>TRM THEN 2240
2220 NEXT J
2230 '
2240 IF Y>50 THEN YR=1900 ELSE YR=2000
2250 X=YR+Y
2260 PRINT STRING$(80,32);:LOCATE CSRLIN-1
2270 PRINT STRING$(80,196);
2280 PRINT "Total";X;TAB(34);USING A$;T;:PRINT TAB(47);USING A$;S
2290 TT=TT+T:TS=TS+S          'tt=tot.prin.to dat:ts=tot.int.to date
2300 PRINT "Total to date";TAB(34);USING A$;TT;:PRINT TAB(47);USING A$;TS
2310 LOCATE 24:PRINT UL$;
2320 K=1:Y=Y+1
2330 IF U>TRM THEN VIEW PRINT:GOSUB 2500:GOTO 270
2340 VIEW PRINT:GOSUB 2500
2350 VIEW PRINT 9 TO 24:CLS:LOCATE 9:GOTO 2000
2360 '
2370 '
2380 '.....preface
2390 PRINT " While this program is intended primarily to calculate real estat";
2400 PRINT "e mortgages,  "
2410 PRINT " it can also be used to calculate equal monthly payments commonly";
2420 PRINT " offered by   "
2430 PRINT " vendors of comsumer products. To do this, enter the price of the";
2440 PRINT " product as   "
2450 PRINT " the amount of the mortgage and enter 12 as the number of times p";
2460 PRINT "er year the   "
2470 PRINT " interest is compounded."
2480 RETURN
2490 '
2500 'PRT
2510 KEY OFF:GOSUB 2580:LOCATE 25,5:COLOR 0,2
2520 PRINT " Send this page to:(1)Printer Queue? (2)Printout? ";
2530 PRINT "(3)Next page? (1/2/3)";:COLOR 7,0
2540 Z$=INKEY$:IF Z$<"1"OR Z$>"3"THEN 2540 ELSE GOSUB 2580
2550 IF Z$="3"THEN RETURN
2560 FOR I%=1 TO 24:FOR J%=1 TO 80:LPRINT CHR$(SCREEN(I%,J%));:NEXT J%:NEXT I%
2570 IF Z$="2"THEN LPRINT CHR$(12) ELSE 2510
2580 LOCATE 25,1:PRINT STRING$(80,32);:RETURN
