10 DEF FNA(N9)=(1-(R2+1)^(-N9))/R2
20 DEF FNR(Z9)=.01*INT(Z9*100+.5)
30 PRINT 
40 PRINT " ","LOAN AMORTIZATION PROGRAM"
50 PRINT 
60 PRINT "DO YOU WISH A DESCRIPTION? TYPE YES OR NO:";
70 INPUT R1$
80 IF R1$="NO" THEN 170
90 PRINT 
100 PRINT "THIS PROGRAM COMPUTES MORTGAGE LOAN VALUES AND"
110 PRINT "WILL PRINT AN AMORTIZATION SCHEDULE GIVEN ANY"
120 PRINT "THREE OF THE FOUR LOAN VALUES:"
130 PRINT "1) INTEREST RATE"
140 PRINT "2) MONTHLY PAYMENT"
150 PRINT "3) LIFE OF THE LOAN"
160 PRINT "4) AMOUNT OF THE LOAN"
170 PRINT 
180 PRINT "ENTER VALUES FOR 3 OF THE 4 FOLLOWING INPUTS"
190 PRINT "AND A ZERO FOR THE ONE YOU WISH COMPUTED...."
200 PRINT 
210 PRINT "AMOUNT OF THE LOAN"
220 INPUT A2
230 A2=ABS(A2)
240 PRINT "MONTHLY PAYMENT"
250 INPUT P2
260 P2=ABS(P2)
270 PRINT "INTEREST RATE  (E.G.  5 1/4% WOULD BE  5.25)"
280 INPUT R2
290 A3=ABS(R2)
300 R2=A3/1200
310 PRINT "LIFE OF THE LOAN  (E.G. 8 YEARS 2 MONTHS WOULD BE  8.02)"
320 INPUT L1
330 L1=ABS(L1)
340 Y2=INT(L1)
350 M2=INT(100*(L1-Y2)+.9)
360 IF M2<12 THEN 390
370 PRINT "INVALID INPUT - TRY AGAIN!"
380 GO TO 310
390 N2=12*Y2+M2
400 K3=0
410 IF R2<>0 THEN 430
420 K3=K3+1
430 IF P2<>0 THEN 450
440 K3=K3+1
450 IF N2<>0 THEN 470
460 K3=K3+1
470 IF A2<>0 THEN 490
480 K3=K3+1
490 IF K3=1 THEN 530
500 PRINT 
510 PRINT "SORRY, I DON'T KNOW WHICH ONE TO COMPUTE."
520 GO TO 170
530 PRINT 
540 PRINT 
550 IF R2=0 THEN 780
560 IF A2=0 THEN 1010
570 IF P2=0 THEN 1060
580 REM FIND LIFE
590 IF P2*FNA(1)<=A2 THEN 620
600 PRINT " ","LIFE OF THE LOAN IS LESS THAN 1 MONTH!"
610 GO TO 170
620 FOR N1=1 TO 9999 STEP 12
630 A1=P2*FNA(N1)
640 IF A1>A2 THEN 670
650 IF A1=A2 THEN 720
660 NEXT N1
670 J=N1-11
680 FOR N2=J TO N1
690 A1=P2*FNA(N2)
700 IF A1>=A2 THEN 730
710 NEXT N2
720 N2=N1
730 Y2=INT(N2/12)
740 M2=INT(N2-12*Y2)
750 PRINT " ","LOAN PERIOD IS ";Y2;"YEARS";M2;"MONTHS"
760 GO TO 1090
770 REM FIND INTEREST RATE
780 IF P2*N2>=A2 THEN 810
790 PRINT " ","LOAN CAN NOT BE REPAID AT $";P2;"A MONTH"
800 GO TO 170
810 X=0
820 IF P2*N2<=A2 THEN 960
830 FOR I=1 TO 9999
840 R2=I/1200
850 A1=P2*FNA(N2)
860 IF A1<A2 THEN 910
870 IF A1<>A2 THEN 900
880 X=I
890 GO TO 960
900 NEXT I
910 X=I-.99
920 X=X+1.0000000000000E-03
930 R2=X/1200
940 A1=P2*FNA(N2)
950 IF A1-1.0000000000000E-05*A2>A2 THEN 920
960 R2=X/1200
970 A3=1.0000000000000E-03*INT(1000*(X+5.0000000000000E-04))
980 PRINT " ","ANNUAL INTEREST RATE IS ";A3;"%"
990 GO TO 1090
1000 REM FIND AMOUNT OF LOAN
1010 A2=P2*FNA(N2)
1020 A8=FNR(A2)
1030 PRINT " ","AMOUNT OF LOAN IS $";A8
1040 GO TO 1090
1050 REM FIND MONTHLY PAYMENT
1060 P2=A2/FNA(N2)
1070 P8=FNR(P2)
1080 PRINT " ","MONTHLY PAYMENT IS $";P8
1090 I2=0
1100 A1=A2
1110 FOR K=1 TO N2
1120 I3=FNR(A1*R2)
1130 I2=I2+I3
1140 A1=A1-P2+I3
1150 NEXT K
1160 PRINT " ","TOTAL INTEREST ON LOAN IS $";FNR(I2)
1170 PRINT 
1180 PRINT 
1190 PRINT "DO YOU WISH AN AMORTIZATION SCHEDULE? TYPE YES OR NO:";
1200 INPUT R1$
1210 IF R1$="YES" THEN 1280
1220 PRINT 
1230 PRINT "ANOTHER ANALYSIS? TYPE YES OR NO:";
1240 INPUT R1$
1250 PRINT 
1260 IF R1$="YES" THEN 200
1270 GO TO 1810
1280 PRINT 
1290 PRINT "TYPE 1 FOR ANNUAL TABLE, 2 FOR MONTHLY"
1300 INPUT K2
1310 PRINT 
1320 PRINT 
1330 PRINT " ","* * *  MORTGAGE TABLE  * * *"
1340 PRINT 
1350 A8=FNR(A2)
1360 PRINT "AMOUNT OF LOAN  $";A8,"ANNUAL INTEREST RATE";A3;"%"
1370 P8=FNR(P2)
1380 PRINT "MONTHLY PAYMENT $";P8,"REPAID IN";Y2;"YEARS";M2;"MONTHS"
1390 PRINT "TOTAL  INTEREST $";FNR(I2)
1400 PRINT 
1410 PRINT 
1420 PRINT " ","AMORTIZATION SCHEDULE"
1430 PRINT 
1440 PRINT 
1450 PRINT " ENDING","PRINCIPAL","INTEREST"
1460 PRINT "PRINCIPAL","  PAID","  PAID"
1470 M=0
1480 K=0
1490 A1=A2
1500 T1=0
1510 T2=0
1520 FOR J=1 TO N2+1
1530 K=K+1
1540 X7=FNR(A1*R2)
1550 P7=P2-X7
1560 IF P7<=A1 THEN 1580
1570 P7=A1
1580 T1=T1+X7
1590 T2=T2+P7
1600 A1=A1-P7
1610 IF K2=1 THEN 1670
1620 IF P7+X7=0 THEN 1690
1630 D1=FNR(A1)
1640 D2=FNR(P7)
1650 D3=FNR(X7)
1660 PRINT D1,D2,D3
1670 IF P7+X7=0 THEN 1690
1680 IF K<12 THEN 1780
1690 M=M+1
1700 IF A1+T1+T2=0 THEN 1750
1710 D1=FNR(A1)
1720 D2=FNR(T2)
1730 D3=FNR(T1)
1740 PRINT D1,D2,D3,"YEAR";M;"TOTALS"
1750 T1=0
1760 T2=0
1770 K=0
1780 NEXT J
1790 PRINT 
1800 GO TO 1220
1810 END
