      PROGRAM PGM04
************************************************************************
*    PROGRAMMER: B. Alex Bridges
*    CLASS:      9:00AM
*    PROGRAM:    PGM04.F
*    DUE DATE:   02/04/99
*
* Program Description:
*    This program reads meter readings from a data file. It uses the
*    readings to calculate the resulting charges incurred over a
*    month's time.
* Variables:
*    NAMEF  : customer's first name
*    NAMEL  : customer's last name
*    READP  : meter reading for previous month
*    READC  : meter reading for current month
*    VOLUME : total amount of gas used for the month
*    WORKING: working amount of gas used for month
*    TEMPV  : temp. amount of gas used for the month
*    COST   : total cost of gas used for the month
*    TEMPC  : temp. cost of gas used for month
*    UNIT   : cost per cubic meter of gas
* Input     : NAMEF,NAMEL,READP,READC
* Output    : TEMPV,UNIT,TEMPC,VOLUME,COST
************************************************************************
        CHARACTER*5 NAMEF,NAMEL*7
        REAL READP,READC,VOLUME,WORKING,TEMPV,COST,TEMPC,UNIT

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

* read in values for name and 2 meter readings
        READ (12, *), NAMEF, NAMEL
 10     READ (12, *, END=20), READP, READC

* calculate the total amount of gas used for the month
        IF (READC .GE. READP) THEN
          VOLUME = READC - READP
        ELSE
          VOLUME = (10000. - READP) + READC
        ENDIF

* display the ouput header
        PRINT '(T30, "INPUT DATA AND CALCULATIONS")'
        PRINT '(T30, "BAB''S GAS TO BURN, INC.",/)'
        PRINT '(T10,
     1  "---------------------------------------------------",)'
        PRINT '(T10,
     1  "|        GAS USED        |          RATE          |",)'
        PRINT '(T10,
     1  "---------------------------------------------------",)'
        PRINT '(T10,
     1  " First 70 cubic meters    $5.00 minimum cost       ",)'
        PRINT '(T10,
     1  " Next 100 cubic meters    $0.050 per cubic meter   ",)'
        PRINT '(T10,
     1  " Next 230 cubic meters    $0.025 per cubic meter   ",)'
        PRINT '(T10,
     1  " Above 400 cubic meters   $0.015 per cubic meter   ",)'
        PRINT '(T10,
     1  "---------------------------------------------------",//)'

* calculate the total cost of gas used for the month
        WORKING = VOLUME
        IF (WORKING .GT. 70) THEN
          TEMPV = 70.
          WORKING = WORKING - TEMPV
          TEMPC = 5.00
          COST = TEMPC
          PRINT '(F4, T6, "Cubic Meters at", T22, "------", " Cost",
     1    T34, F4.2, " MINIMUM CHARGE")', TEMPV, TEMPC
        ELSE
          TEMPV = WORKING
          WORKING = 0
          TEMPC = 5.00
          COST = TEMPC
          PRINT '(F4, T6, "Cubic Meters at", T22, "------", " Cost",
     1    T34, F4.2, " MINIMUM CHARGE")', TEMPV, TEMPC
        ENDIF
        IF (WORKING .GT. 100) THEN
          TEMPV = 100.
          WORKING = WORKING - TEMPV
          UNIT = 0.050
          TEMPC = UNIT * TEMPV
          COST = COST + TEMPC
          PRINT '(F4, T6, "Cubic Meters at", T22, F6.4, " Cost",
     1    T34, F4.2)', TEMPV, UNIT, TEMPC
        ELSE
          TEMPV = WORKING
          WORKING = 0
          UNIT = 0.050
          TEMPC = UNIT * TEMPV
          COST = COST + TEMPC
          PRINT '(F4, T6, "Cubic Meters at", T22, F6.4, " Cost",
     1    T34, F4.2)', TEMPV, UNIT, TEMPC
        ENDIF
        IF (WORKING .GT. 230) THEN
          TEMPV = 230.
          WORKING = WORKING - TEMPV
          UNIT = 0.025
          TEMPC = UNIT * TEMPV
          COST = COST + TEMPC
          PRINT '(F4, T6, "Cubic Meters at", T22, F6.4, " Cost",
     1    T34, F4.2)', TEMPV, UNIT, TEMPC
        ELSE
          TEMPV = WORKING
          WORKING = 0
          UNIT = 0.025
          TEMPC = UNIT * TEMPV
          COST = COST + TEMPC
          PRINT '(F4, T6, "Cubic Meters at", T22, F6.4, " Cost",
     1    T34, F4.2)', TEMPV, UNIT, TEMPC
        ENDIF
        IF (WORKING .GT. 0) THEN
          TEMPV = WORKING
          WORKING = 0
          UNIT = 0.015
          TEMPC = UNIT * TEMPV
          COST = COST + TEMPC
          PRINT '(F4, T6, "Cubic Meters at", T22, F6.4, " Cost",
     1    T34, F4.2)', TEMPV, UNIT, TEMPC
        ENDIF
        PRINT '(//)'

* display the output
        PRINT '(T30, "BAB''S GAS TO BURN, INC.",/)'
        PRINT '("PREVIOUS MONTH''S READING:  ", F8.2, T40,
     1  "CUBIC METERS")', READP
        PRINT '(" CURRENT MONTH''S READING:  ", F8.2, T40,
     1  "CUBIC METERS")', READC
        PRINT '("                   TOTAL:  ", F8.2, T40,
     1  "CUBIC METERS",/)', VOLUME
        PRINT '("            TOTAL BILLING:  ", F8.2, /)', COST
        PRINT '("   ---   PLEASE MAKE CHECKS PAYABLE TO:",/)'
        PRINT '(T20, "BAB''S GAS TO BURN, INC.")'
        PRINT '(T5, "THANK YOU",/)'
        PRINT '(A,A,/,"President and CEO")', NAMEF, NAMEL

* advance page and repeat above for next data set
        PRINT '(////////////////////////)'
        GOTO 10

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

