rem Program to compute loan repayment
    Dim line$(100)
    Dim DaysInMonth$/31,28,31,30,31,30,31,31,30,31,30,31/
    Input "Loan Amount/Date: " Line$
    Gosub BreakLineIntoAmountAndDate
    Principal=Amount
    LastPaymentDate=Date
    Input "Percent interest rate, compounded annually: " InterestRate
    InterestRate=1+InterestRate/100
    Repeat
       Input "Payment amount/date " Line$
       Gosub BreakLineIntoAmountAndDate
       DistanceBetweenPayments=Date-LastPaymentDate
       LastPaymentDate=Date
       Principal=Principal * (InterestRate^(DistanceBetweenPayments/365))
       Principal=Principal - Amount
       Print "Amount Remaining = ";Principal
       If Principal <=0 then exit
    End

BreakLineIntoAmountAndDate:
   Rem line has format   xxx.xxxx   mm/dd/yy
   Let Amount=Val(Line$)
   let Line$=Right$(Line$,Find(Line$," ")+1)
   Let month=val(Line$)
   let Line$=Right$(Line$,Find(Line$,"/")+1)
   Let day=val(Line$)
   let Line$=Right$(Line$,Find(Line$,"/")+1)
   Let year=val(Line$)
   Let date=year*365+day
   For i=1 to month-1 do date=date+DaysInMonth$[i]
!   Print "amount month day year date";amount;month;day;year;date
   Return

END
