!------------------------------------------------
!
!  Finance
!
!  This program prints the balance on an
!  account for monthly payments, along with the
!  total amount paid so far.
!
!------------------------------------------------
!
LOANAMOUNT = 10000.0			: ! amount of the loan
PAYMENT = 600.0				: ! monthly payment
INTEREST = 15				: ! yearly interest (as %)
!
DIM balance				: ! amount left to pay
DIM monthlyInterest			: ! multiplier for interest
DIM paid				: ! total amount paid
DIM month AS INTEGER			: ! month number
DIM use$				: ! format string
!
! set up the initial values
!
balance = LOANAMOUNT
paid = 0
month = 0
monthlyInterest = 1.0 + INTEREST/1200.0
!
! write out the conditions
!
PRINT USING "Payment schedule for a loan of $$####.##"; LOANAMOUNT
PRINT USING "with monthly payments of $$##.## at an"; PAYMENT
PRINT USING "interest rate of #%."; INTEREST
PRINT
PRINT "          month        balance    amount paid"
PRINT "          -----        -------    -----------"
use$ =" ############## $$#########.## $$#########.##"
!
! check for payments that are too small
!
IF balance*monthlyInterest - balance >= PAYMENT THEN
   PRINT "The payment is too small!"
ELSE
   WHILE balance > 0
      ! add in the interest
      balance = balance*monthlyInterest
      ! make a payment
      IF balance > PAYMENT THEN
         balance = balance - PAYMENT
         paid = paid + PAYMENT
      ELSE
         paid = paid + balance
         balance = 0
      END IF
      ! update the month number
      month = month + 1
      ! write the new statistics
      PRINT USING use$; month, balance, paid
   WEND
END IF
