      PROGRAM PGM05
************************************************************************
*    PROGRAMMER: B. Alex Bridges
*    CLASS:      9:00AM
*    PROGRAM:    PGM05.F
*    DUE DATE:   02/11/99
*
* Program Description:
*    This program reads loan information from a data file. It uses the
*    values to determine the amortization table for the life of the
*    loan.
* Variables:
*    NAMEF   : student's first name
*    NAMEL   : student's last name
*    LOAN    : amount of the loan
*    IRATE   : interest rate of the loan
*    LENGTH  : length of the loan
*    NUMBER  : payment number for the loan
*    MPAYC   : current monthly payment for the loan
*    MPAYT   : total monthly payments for the loan
*    IPAIDC  : current interest paid for the loan
*    IPAIDT  : total interest paid for the loan
*    PRCPLEC : current principle for the loan
*    PRCPLET : total principle for the loan
*    BALANCE : current balance for the loan
* Input     : NAMEF,NAMEL,LOAN,INTRST,LENGTH
* Output    : MPAYC,MPAYC,IPAIDC,IPAIDC,PRCPLEC,PRCPLET,BALANCE
************************************************************************

        CHARACTER*5 NAMEF,NAMEL*7
        REAL LOAN,IRATE,MPAYC,MPAYT,IPAIDC,IPAIDT,PRCPLEC,PRCPLET,BALANC
        INTEGER LENGTH,NUMBER

* open the data file
        OPEN (UNIT=12, FILE="pgm05.dat")

* read in values for name and 2 meter readings
        READ (12, *), NAMEF, NAMEL
 10     READ (12, *, END=99), LOAN,IRATE,LENGTH

* display the output header
        PRINT '(T30, "LOAN INPUT DATA",/)'
        PRINT '("STUDENT NAME:",T32,A,A)', NAMEF,NAMEL
        PRINT '("LOAN AMOUNT:",T32,F8.2)', LOAN
        PRINT '("INTEREST RATE (Annual):",T32,F5.2)', IRATE
        PRINT '("LENGTH OF LOAN (Annual):",T32,I2,//)', LENGTH

* convert from annually from monthly
        IRATE = IRATE / 12
        LENGTH = LENGTH * 12

* calculate the monthly payment
        MPAYC = LOAN * ( ( IRATE * ( (1 + IRATE)**(LENGTH) ) ) /
     1   ( (1 + IRATE)**(LENGTH) - 1 ) )

* display the output footer
        PRINT '(T30,"AMORTIZATION TABLE",/)'
        PRINT '("MONTHLY PAYMENT:",T18,F8.2,/)', MPAYC
        PRINT '("PAYMENT",T10,"MONTHLY",T20,"INTEREST",T30,"",
     1   T40,"BALANCE")'
        PRINT '("NUMBER",T10,"PAYMENT",T20,"PAID",T30,"PRINCIPLE",
     1   T40,"DUE")'
        BALANC = LOAN
        DO 30 NUMBER = 1,LENGTH,1
          IPAIDC = BALANC * IRATE
          PRCPLEC = MPAYC - IPAIDC
          BALANC = BALANC - PRCPLEC
          MPAYT = MPAYT + MPAYC
          IPAIDT = IPAIDT + IPAIDC
          PRCPLET = PRCPLET + PRCPLEC
          PRINT 20,NUMBER,MPAYC,IPAIDC,PRCPLEC,BALANC
 20       FORMAT (2X,I2,5X,F7.2,2X,F7.2,3X,F8.2,3X,F8.2)
 30     CONTINUE
        PRINT '("")'
        PRINT 40,"TOTALS",MPAYT,IPAIDT,PRCPLET
 40     FORMAT (1X,A,1X,F8.2,1X,F8.2,3X,F8.2)
        PRINT '("")'

* close the data file and print end of program message
 99     CLOSE (12)
        PRINT '(T28, "End of program - PGM05.F")'
        END

************************************************************************
