% hw028.m
%
%  Pay for groceries at the automatic checkout.
%
owed = 10.00 + 90.0 * rand ( );
%
%  Try to make the amount an exact number of cents.
%
owed = ( round ( 100 * owed ) ) / 100;
%
%  Until amount is paid, accept another bill from user.
%
paid = 0.0;

while ( paid < owed )

  fprintf ( '  Amount due is %8.2f:\n', owed - paid );
  bill = input ( '  Insert a bill such as 1, 5, 10, 20, 50, or 100: ' );
  paid = paid + bill;

end

fprintf ( '  $%8.2f paid\n', paid );
fprintf ( '  $%8.2f groceries\n', owed );
fprintf ( '  $%8.2f change back\n', paid - owed );

