SOURCE FILE: 170_changer.cpp



#include <iostream>
using namespace std ;

int main (void)
{
   double the_price, the_payment, change_owed ;

   cout << "\nEnter the item price: " ;
   cin >> the_price ;

   cout << "\nEnter the item payment (>= the price): " ;
   cin >> the_payment ;

   if (the_payment < the_price) cout << "\nError!\n" ;
   else 
   {
      change_owed = the_payment - the_price ;
      cout << endl ;
      while (change_owed > 0)
      {
        if (change_owed >= 1.00) 
        {  
          cout << "Here is a dollar\n" ;
          change_owed -= 1.00 ;
        }
        else if (change_owed >= 0.50)
             {  
               cout << "Here is a half-dollar\n" ;
               change_owed -= 0.50 ;
             }
        else if (change_owed >= 0.25)
             {  
               cout << "Here is a quarter\n" ;
               change_owed -= 0.25 ;
             }
        else if (change_owed >= 0.10)
             {  
               cout << "Here is a dime\n" ;
               change_owed -= 0.10 ;
             }
        else if (change_owed >= 0.05)
             {  
               cout << "Here is a nickel\n" ;
               change_owed -= 0.05 ;
             }
        else if (change_owed > 0)
             {  
               cout << "Here is a penny\n" ;
               change_owed -= 0.01 ;
             }
      }
   }
   return 0;
}