/*
 * hw1.cxx - This program takes as input the price of an item and the cash tendered by
 *             the customer, and outputs the cash to be returned so that the number of 
 *             coins is a minimum. 
 *             Note: no error checking is performed on the input. It is assumed that the 
 *             cash tendered is enough to cover the total of the purchases. 
 *
 * written by:  Patty Elliott
 *              pe172
 *              CS1005 section C01, C02, C03
 *              1/11/03
 */

#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{
    double total = 0.0;                 // total purchases made by customer       
    double cashTendered = 0.0;          // amount of cash received from customer    
    double change = 0.0;                // change to be given to customer

    int dollars = 0;                    // dollars to be given as change to customer                 
    int coinsLeft = 0;                  // remaining change to be given to customer             
    int numQuarters = 0, numDimes = 0, numNickels = 0; 


    // Get input. Get the total amount of purchases made by the customer 
    // and the cash received from the customer. Assume cash received is 
    // larger than total purchases. Assume valid input. 

    cout << "This program will calculate your change, given the cost of your "<< endl;
    cout << "purchases and the amount of money tendered. The minimum number " << endl;
    cout << "of coins will be returned in your change." << endl << endl;

    cout << "Enter the total amount of your purchases: $";
    cin >> total; 

    cout << "Enter the amount of cash tendered: $";
    cin >> cashTendered; 

    // Calculate and display the amount of change to be given to the customer
    // Display 2 digits to the right of the decimal point. 

    change = cashTendered - total; 
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout << setprecision (2); 
    cout << "\nThe cash to be returned is $" << change << endl;

    
    // Calculate the number and type of coins to be given to the customer
    // Use .005 for rounding. 
    // Example of algorithm used. 
    //    Change due customer = (5.32666666)
    //    Round up to the nearest penny (5.33)
    //    Get the fractional part (.33) and multiply by 100 to turn it into a whole number
    //    so that you can use integer math for the remaining calculations.
    //    Divide that number by 25 to see how many quarters to give to the customer
    //    Subtract off the amount already given to customer as quarters. 
    //    Repeat the process for dimes (division by 10), nickels (division by 5)
    //    and what's left is the pennies. 

    dollars = change;   
    coinsLeft = (change - dollars) * 100 + .005;    //.005 is the rounding factor

    numQuarters = coinsLeft / 25; 
    coinsLeft  = coinsLeft - (numQuarters * 25); 
    cout << "The number of quarters returned is " << numQuarters << endl;

    numDimes = coinsLeft / 10; 
    coinsLeft = coinsLeft - (numDimes * 10); 
    cout << "The number of dimes returned is " << numDimes << endl;

    numNickels = coinsLeft / 5; 
    coinsLeft = coinsLeft - (numNickels * 5); 
    cout << "The number of nickels returned is " << numNickels << endl;

    cout << "The number of pennies returned is " << coinsLeft << endl;

    return 0;
}