// Marvyn Jesse De La Torre     CS1A     Chapter 6, p. 372, #13
//
/*************************************************************************
 * DISPLAY COPPER WIRE ORDER STATUS
 * This program displays the number of spools ready to ship, backordered,
 * and the total charges for the spools ready to ship.
 *
 * INPUT
 *   Spools ordered, spools in stock, and special shipping charge
 *
 * OUTPUT
 *   Spools ready to ship, backordered, and total charges
 *************************************************************************/

#include <iomanip>
#include <iostream>
using namespace std;

const double SPOOL_PRICE = 100.00;
const double STANDARD_SHIPPING = 10.00;

// Function Prototype
void displayOrderStatus(int spoolsOrdered, int spoolsInStock,
                        double shippingCharge = STANDARD_SHIPPING);

int main()
{
    int spoolsOrdered, spoolsInStock;
    char answer;
    double shippingCharge;

    cout << "Number of spools ordered: ";
    cin >> spoolsOrdered;

    cout << "Number of spools in stock: ";
    cin >> spoolsInStock;

    cout << "Are there special shipping charges? (Y/N): ";
    cin >> answer;

    if (answer == 'Y' || answer == 'y')
    {
        cout << "Special shipping charge per spool: $";
        cin >> shippingCharge;

        displayOrderStatus(spoolsOrdered, spoolsInStock, shippingCharge);
    }
    else
    {
        displayOrderStatus(spoolsOrdered, spoolsInStock);
    }

    return 0;
}

/*************************************************************************
 * displayOrderStatus
 * Displays the order status and charges for spools ready to ship.
 *************************************************************************/
void displayOrderStatus(int spoolsOrdered, int spoolsInStock,
                        double shippingCharge)
{
    int readyToShip = spoolsOrdered;

    if (spoolsInStock < readyToShip)
        readyToShip = spoolsInStock;

    int backordered = spoolsOrdered - readyToShip;
    double subtotal = readyToShip * SPOOL_PRICE;
    double shippingTotal = readyToShip * shippingCharge;
    double orderTotal = subtotal + shippingTotal;

    cout << fixed << setprecision(2);
    cout << "\nORDER STATUS" << endl;
    cout << "Spools ready to ship: " << readyToShip << endl;
    cout << "Spools on backorder: " << backordered << endl;
    cout << "Subtotal: $" << subtotal << endl;
    cout << "Shipping and handling: $" << shippingTotal << endl;
    cout << "Total ready to ship: $" << orderTotal << endl;
}