fork download
  1. // Marvyn Jesse De La Torre CS1A Chapter 6, p. 372, #13
  2. //
  3. /*************************************************************************
  4.  * DISPLAY COPPER WIRE ORDER STATUS
  5.  * This program displays the number of spools ready to ship, backordered,
  6.  * and the total charges for the spools ready to ship.
  7.  *
  8.  * INPUT
  9.  * Spools ordered, spools in stock, and special shipping charge
  10.  *
  11.  * OUTPUT
  12.  * Spools ready to ship, backordered, and total charges
  13.  *************************************************************************/
  14.  
  15. #include <iomanip>
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. const double SPOOL_PRICE = 100.00;
  20. const double STANDARD_SHIPPING = 10.00;
  21.  
  22. // Function Prototype
  23. void displayOrderStatus(int spoolsOrdered, int spoolsInStock,
  24. double shippingCharge = STANDARD_SHIPPING);
  25.  
  26. int main()
  27. {
  28. int spoolsOrdered, spoolsInStock;
  29. char answer;
  30. double shippingCharge;
  31.  
  32. cout << "Number of spools ordered: ";
  33. cin >> spoolsOrdered;
  34.  
  35. cout << "Number of spools in stock: ";
  36. cin >> spoolsInStock;
  37.  
  38. cout << "Are there special shipping charges? (Y/N): ";
  39. cin >> answer;
  40.  
  41. if (answer == 'Y' || answer == 'y')
  42. {
  43. cout << "Special shipping charge per spool: $";
  44. cin >> shippingCharge;
  45.  
  46. displayOrderStatus(spoolsOrdered, spoolsInStock, shippingCharge);
  47. }
  48. else
  49. {
  50. displayOrderStatus(spoolsOrdered, spoolsInStock);
  51. }
  52.  
  53. return 0;
  54. }
  55.  
  56. /*************************************************************************
  57.  * displayOrderStatus
  58.  * Displays the order status and charges for spools ready to ship.
  59.  *************************************************************************/
  60. void displayOrderStatus(int spoolsOrdered, int spoolsInStock,
  61. double shippingCharge)
  62. {
  63. int readyToShip = spoolsOrdered;
  64.  
  65. if (spoolsInStock < readyToShip)
  66. readyToShip = spoolsInStock;
  67.  
  68. int backordered = spoolsOrdered - readyToShip;
  69. double subtotal = readyToShip * SPOOL_PRICE;
  70. double shippingTotal = readyToShip * shippingCharge;
  71. double orderTotal = subtotal + shippingTotal;
  72.  
  73. cout << fixed << setprecision(2);
  74. cout << "\nORDER STATUS" << endl;
  75. cout << "Spools ready to ship: " << readyToShip << endl;
  76. cout << "Spools on backorder: " << backordered << endl;
  77. cout << "Subtotal: $" << subtotal << endl;
  78. cout << "Shipping and handling: $" << shippingTotal << endl;
  79. cout << "Total ready to ship: $" << orderTotal << endl;
  80. }
Success #stdin #stdout 0s 5300KB
stdin
10 6 Y 5 
stdout
Number of spools ordered: Number of spools in stock: Are there special shipping charges? (Y/N): Special shipping charge per spool: $
ORDER STATUS
Spools ready to ship: 6
Spools on backorder: 4
Subtotal: $600.00
Shipping and handling: $30.00
Total ready to ship: $630.00