PROGRAM CashBills (Input,Output);

(* David Wills
   University of Maryland  CMIS 102
   12 April 1991
   Turbo Pascal 5.5    *)

(* This program prompts the user for an amount of dollars and then
   computes the minimum number of U.S. bills needed to equal that
   amount.  *)

CONST
   Hundred = 100;      (* Values of the bill denominations *)
   Fifty = 50;
   Twenty = 20;
   Ten = 10;
   Five = 5;
   One = 1;

VAR
   Sum : Integer;      (* Dollars amount, user input *)
   Bills : Integer;    (* Number of bills of each denomination *)
   LeftOver : Integer; (* Dollar amount left over after subtracting
                          bills of higher denomination *)


(*****************************************************************)
(*This procedure computes the number of bills of a given denomination
that evenly divide into an amount of dollars.  It also computes the
remainder of dollars after subtracting the value of the bills *)

PROCEDURE NextBills (Denomination : Integer;
                     VAR NumOfBills, Remainder : Integer);

Begin
   NumOfBills := Remainder DIV Denomination;
   Remainder := Remainder MOD Denomination;
End;



BEGIN  (* CashBills *)
   Writeln('This program calculates the minimum number of bills');
   Writeln('that add up to a user-specified dollar amount.');
   Writeln('Enter a dollar amount:');
   Readln(Sum);

   LeftOver := Sum;

   NextBills(Hundred,Bills,LeftOver);
   Writeln('Number of hundreds = ',Bills);

   NextBills(Fifty,Bills,LeftOver);
   Writeln('Number of fifties = ',Bills);

   NextBills(Twenty,Bills,LeftOver);
   Writeln('Number of twenties = ',Bills);

   NextBills(Ten,Bills,LeftOver);
   Writeln('Number of tens = ',Bills);

   NextBills(Five,Bills,LeftOver);
   Writeln('Number of fives = ',Bills);

   Writeln('Number of ones = ',LeftOver);
END.  (* CashBills *)