Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip> // std::setprecision
  3. using namespace std;
  4.  
  5. // Function Declarations
  6. void readInputData(int& spoolsOrdered, int& spoolsInStock, double& shippingCharges);
  7. void display(int spoolsOrdered, int spoolsInStock, double shippingCharges);
  8. int main()
  9. {
  10. // Declaring variables
  11. int spoolsOrdered, spoolsInStock;
  12. double shippingCharges;
  13.  
  14. // Calling the functions
  15. readInputData(spoolsOrdered, spoolsInStock, shippingCharges);
  16. display(spoolsOrdered, spoolsInStock, shippingCharges);
  17.  
  18. return 0;
  19. }
  20.  
  21. // This function will read the inputs entered by the user
  22. void readInputData(int& spoolsOrdered, int& spoolsInStock, double& shippingCharges)
  23. {
  24.  
  25. /* This while loop continues to execute
  26. * until the user enters a valid number
  27. */
  28. while (true)
  29. {
  30. cout << "Spools to be ordered :";
  31. cin >> spoolsOrdered;
  32. if (spoolsOrdered < 1)
  33. {
  34. cout << "** Spools Order must be 1 or more **" << endl;
  35. continue;
  36. }
  37. else
  38. break;
  39. }
  40.  
  41. /* This while loop continues to execute
  42. * until the user enters a valid number
  43. */
  44. while (true)
  45. {
  46. cout << "Spools in Stock :";
  47. cin >> spoolsInStock;
  48. if (spoolsInStock < 1)
  49. {
  50. cout << "** Spools in stock must be 0 or more **" << endl;
  51. continue;
  52. }
  53. else
  54. break;
  55. }
  56.  
  57.  
  58. char ch;
  59.  
  60. cout << "Special shipping and handling (y or n):";
  61. cin >> ch;
  62.  
  63. if (ch == 'y')
  64. {
  65. /* This while loop continues to execute
  66. * until the user enters a valid number
  67. */
  68. while (true)
  69. {
  70. cout << "Enter Special Shipping charges :";
  71. cin >> shippingCharges;
  72. if (shippingCharges < 0)
  73. {
  74. cout << "** The spool shipping and handling charge must be 0.0 or more **" << endl;
  75. continue;
  76. }
  77. else
  78. break;
  79. }
  80. }
  81. else
  82. {
  83. shippingCharges = 11.88;
  84. }
  85. }
  86.  
  87. // This function will display the output
  88. void display(int spoolsOrdered, int spoolsInStock, double shippingCharges)
  89. {
  90. // Setting the precision to two decimal places
  91. std::cout << std::setprecision(2) << std::fixed;
  92.  
  93. cout << "Spools ready to ship :" << spoolsInStock << endl;
  94. cout << "Spools on back-order :" << spoolsOrdered - spoolsInStock << endl;
  95. double subtotal = spoolsInStock * 100;
  96. cout << "Subtotal ready to ship: $" << setw(10) << subtotal << endl;
  97. cout << "Shipping and handling :$" << setw(10) << spoolsInStock * shippingCharges << endl;
  98. double total = (spoolsInStock * 100) + (spoolsInStock * shippingCharges);
  99. cout << "Total shipping charges :$" << setw(10) << total << endl;
  100. }
  101.  
  102. _______________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement