      PROGRAM DRIVER
************************************************************************
* This is a driver program to test subroutine DISPEN.  Variables used: *
*   COST   : cost of item                                              *
*   PAID   : amount paid by customer                                   *
*   NUM100 : number of dollars,                                        *
*   NUM25  :    quarters,                                              *
*   NUM10  :    dimes,                                                 *
*   NUM5   :    nickels,                                               *
*   NUM1   :    pennies   to be returned in change                     *
*   RESPON : user response to More data? query                         *
*                                                                      *
* Input : COST of item and amount PAID by customer                     *
* Output: Change in dollars, quarters, dimes, nickels, and pennies     *
************************************************************************

      REAL COST, PAID
      INTEGER NUM100, NUM25, NUM10, NUM5, NUM1
      CHARACTER*1, RESPON

      PRINT *, 'THIS PROGRAM TESTS A CHANGE-DISPENSING SUBROUTINE.'
      PRINT *

*     Do the following until user indicates no more data
 10       CONTINUE
         PRINT *, 'ENTER COST OF ITEM AND AMOUNT PAID BY CUSTOMER:'
         READ *, COST, PAID
         CALL DISPEN(COST, PAID, NUM100, NUM25, NUM10, NUM5, NUM1)
         PRINT 20, NUM100, 'DOLLARS', NUM25, 'QUARTERS',
     +             NUM10, 'DIMES', NUM5, 'NICKELS', NUM1, 'PENNIES'
 20             FORMAT(1X, 'THE CHANGE FROM THIS PURCHASE IS:' /
     +          6(1X, I3, 1X, A /))
         PRINT *
         PRINT *, 'MORE DATA (Y OR N)?'
         READ '(A)', RESPON
         IF (RESPON .EQ. 'Y') GO TO 10

         END


**DISPEN****************************************************************
* Subroutine to compute the dollars, quarters, dimes, nickels, and     *
* pennies in change given the amount of a purchase and the amount paid *
* by the customer.  Local variable used:                               *
*   CHANGE : the amount to be returned in change (in cents)            *
*                                                                      *
* Accepts: AMOUNT of purchase and amount paid by customer (PAY)        *
* Returns: DOLLAR, QUARTR, DIMES, NICKEL, CENTS, the number of         *
*          dollars, quarters, dimes, nickels, and pennies to be        *
*          returned in change.                                         *
************************************************************************

      SUBROUTINE DISPEN(AMOUNT, PAY,
     +           DOLLAR, QUARTR, DIMES, NICKEL, CENTS)

      REAL AMOUNT, PAY
      INTEGER DOLLAR, QUARTR, DIMES, NICKEL, CENTS, CHANGE

*     Calculate amount of change in cents
      CHANGE = ANINT(100 * (PAY - AMOUNT))

      IF (CHANGE .GT. 0) THEN
*        Compute number of dollars
         DOLLAR = CHANGE / 100
         CHANGE = MOD(CHANGE, 100)

*        Compute number of quarters
         QUARTR = CHANGE / 25
         CHANGE = MOD(CHANGE, 25)

*        Compute number of dimes
         DIMES = CHANGE / 10
         CHANGE = MOD(CHANGE, 10)

*        Compute number of nickels and pennies
         NICKEL = CHANGE / 5
         CENTS = MOD(CHANGE, 5)

      ELSE
*        Insufficient payment
         PRINT *, '*** PAYMENT TOO SMALL BY ', -CHANGE, ' CENTS ***'
         DOLLAR = 0
         QUARTR = 0
         DIMES = 0
         NICKEL = 0
         CENTS = 0

      END IF

      END
