! A program to calculate payments on a loan by duration and interest rates.
! begun 5/13/83 by ron
! This program outputs the results of the fancy version to a file called
! AMORTZ.DAT. If you run the program again, it writes the new listing over
! the old one.

! If you want to append several runs, replace OUTPUT with APPEND
! where the file AMORTZ.DAT is opened.

map1 loan,f     ! loan amount in dollars
map1 rate,f     ! interest rate
map1 lenght,f   ! length of loan in years
map1 a,f
map1 dummy,s,1
map1 choice,f

menu:
       ? tab(-1,0)
       ? tab(5,5)
       ? "Here are the choices for running this program"
       ?
       ? "1.  Run just the quickest version..............."
       ?
       ? "2.  Run the fancy one with monthly listings....."
       ?
       ? "3.  Exit this program stage left................"
       ?
       input "Enter the number of your choosing................>",choice

       on choice call the'top, fancy, quit



the'top:
       ? tab(-1,0)
       ? tab(8,10)
       input "Enter loan amount in dollars.......$",loan
       ?
       input "Enter annual interest rate .........",rate
       ?
       input "Enter loan duration in years........",length

calculate:
       let i=rate/12/100
       let m=length*12
       let l=loan
       let a=(i*l)/((1-(i+1)^(-m)))
       goto answer
fancy:
       ? tab(-1,0)
       ? tab(8,10)

       open #1, "AMORTZ.DAT", output
       input "Enter loan amount in dollars......$",loan
       ?#1, "Enter loan amount in dollars......$",loan
       ?
       input "Enter annual interest rate.........",rate
       ?#1, "Enter annual interest rate.........",rate
       ?
       input "Enter loan duration in years.......",length
       ?#1, "Enter loan duration in years.......",length
       let i=rate/12/100
       let m=length*12
       let l=loan
       let a=(i*l)/((1-(i+1)^(-m)))
       let x=a
       let x=(int(100*(x+.005)))/100
       let a=x
       ?#1
       ?#1
       ?#1
       ?
       ?
       ? "The monthly payment is ---------- $",a
       ?#1, "The monthly payment is ---------- $",a
       ?
       ?
       ?#1
       ?#1
       input"For the month by month listing hit RETURN",q
       let b=l                         !initialize for Amortization
       let t=0
       ? "MONTH#","INTEREST","PRINCIPLE","PRINC.BAL","TOTAL INT."
       ?#1, "MONTH#","INTEREST","PRINCIPLE","PRINC.BAL","TOTAL INT."
       for j=1 to m                    !loop for number of payments
       let i1=b*i                      !compute the interest
       let x=i1
       let x=(int(100*(x+.005)))/100
       let i1=x
       let p=a-i1                      !compute the PRINCIPLE
       if j=m then let p=b             !force out the last payment
       let b=b-p                       !update the loan balance
       let t=t+i1                      !update the total interest
       ? j,i1,p,b,t                    !print monthly pay details
       ?#1, j,i1,p,b,t
       next j
       ?
       close #1


!       input "Shall we out put this to a file (Y/N) --->",b$
!       if b$="y" then call format

       input "Shall we do it again (Y/N)----->",a$
       if ucs(a$)="Y"&
            then call menu &
               else goto quit


answer:
       ?tab(15,10)
       ?"The monthly payment on that loan would be       $",a
       call pause
       call menu

pause:
       ? tab(20,25)
       input "hit return to continue.....>",y
       call menu
       return


quit:
       end