// Program:    Cost of a purchase
// Programmer: Bob Comer
//
// This program finds the cost for a given quantity of some
// item to be purchased.
//
// Algorithm:
//   main
//   ----
//     Get the item price and quantity (GetItemInfo)
//     Calculate the cost of purchase  (CalcCost)
//     Print the price, quantity, and cost (PrintCost)
//
//   GetItemInfo
//   -----------
//     Get the item price and quantity
//
//   CalcCost
//   --------
//     Calculate the cost of purchase
//
//   PrintCost
//   ---------
//     Print the price, quantity, and cost
//
//************************************************************

#include <iostream.h>
#include <iomanip.h>

void GetItemInfo( float &price, int &quantity );
float Cost( float price, int quantity );
void PrintCost( float price, int quantity, float cost );

int main()
{
   float price;     // price for a single item
   int quantity;    // quantity of item to be purchased
   float cost;      // purchase cost for given quantity of item

// Get item price and quantity
   GetItemInfo(price, quantity);

// Calculate purchase cost for given quantity of item
   cost = Cost(price, quantity);
   
// Print item information and cost
   PrintCost(price, quantity, cost);

// Signal normal completion
   return 0;
}










//************************************************************
// Function: GetItemInfo
//
// This function gets the item price and quantity.
//************************************************************

void GetItemInfo( float &price, int &quantity )
{
// Get item price and quantity
   cout << "Enter item price and quantity to purchase: ";
   cin >> price >> quantity;
   return;
}


//************************************************************
// Function: Cost
//
// This function calculates the cost for the purchase.
//************************************************************

float Cost( float price, int quantity )
{
// Calculate the cost for the purchase
   return price * quantity;
}


//************************************************************
// Function: PrintCost
//
// This function prints the price, quantity, and cost for the
// purchase.
//************************************************************

void PrintCost( float price, int quantity, float cost )
{
// Print the price, quantity, and cost
   cout << setiosflags(ios::fixed) << setprecision(2);
   cout << endl;
   cout << "Item price: " << setw(8) << price << endl;
   cout << "Quantity  : " << setw(8) << quantity << endl;
   cout << "Total     : " << setw(8) << cost << endl;
   return;
}
