Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. // A painting company has determined that for every 115 sqft
  2. // of wall space one gal of paint and eight hours of labor will be required.
  3. // The company charges 18.00 per hour for labor.
  4. #include <iostream>
  5. #include <iomanip>
  6. using namespace std;
  7.  
  8. // Prototype function
  9. int paintPerGallon();
  10. void roomPolicy();
  11. void validateRooms();
  12.  
  13. // Global constant
  14. const double COMPANY_CHARGES = 18.00;
  15.  
  16.  
  17. // Main
  18. int main()
  19. {
  20. int numOfrooms;
  21. double totalSquareFeet = 0; // accumulator for running total
  22. double numOfGallons, hoursOfLabor;
  23. double costOfPaint, totalLabor;
  24.  
  25.  
  26. // Call function room policy for the user
  27. roomPolicy();
  28.  
  29. // Ask user to enter number of rooms to be painted
  30. cout << "Enter the number of rooms to be painted.\n";
  31. cin >> numOfrooms;
  32.  
  33. // Call function validate rooms for user.
  34. validateRooms();
  35. for (int loop = 1; loop <= numOfrooms; loop++)
  36. {
  37. int rooms;
  38. cout << "Enter the square feet for room " << loop << ":" << endl;
  39. cin >> rooms;
  40. totalSquareFeet += rooms;
  41. }
  42.  
  43. // Format output
  44. cout << fixed << showpoint << setprecision(2);
  45.  
  46. cout << "Total square feet is " << totalSquareFeet << "." << endl;
  47.  
  48. paintPerGallon();
  49.  
  50. numOfGallons = totalSquareFeet / 415;
  51.  
  52. // Calculate hours of labor
  53. hoursOfLabor = numOfGallons * 8;
  54.  
  55. // Calculate cost of paint
  56. costOfPaint = paintPerGallon * numOfGallons;
  57.  
  58. // Calculate total labor
  59. totalLabor = hoursOfLabor * COMPANY_CHARGES;
  60.  
  61. // Let the user know all totals from the paint job
  62. cout << "Total number of gallons used are " << numOfGallons << "." << endl;
  63. cout << "Total hours of labor are " << hoursOfLabor << "." << endl;
  64. cout << "The total cost of the paint is " << costOfPaint << "." << endl;
  65. cout << "Total labor charges will be " << totalLabor << "." << endl;
  66. return 0;
  67. }
  68.  
  69. int paintPerGallon()
  70. {
  71. int paintPerGallon;
  72. cout << "How much is the paint per gallon?\n";
  73. cin >> paintPerGallon;
  74. if (paintPerGallon >= 10)
  75. return paintPerGallon;
  76. else
  77. cout << "That is too cheap for a gallon of paint! Please enter a valid price." << endl;
  78. }
  79.  
  80. void roomPolicy()
  81. {
  82. cout << "Please be advised that we have a one room \n";
  83. cout << "minimum and a fifty room maximum rooms to be painted.\n";
  84. }
  85.  
  86. void validateRooms()
  87. {
  88. int numOfrooms;
  89. while (numOfrooms < 1 || numOfrooms > 50)
  90. {
  91. cout << "Please see our room limit policy!\n";
  92. cin >> numOfrooms;
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement