Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A painting company has determined that for every 115 sqft
- // of wall space one gal of paint and eight hours of labor will be required.
- // The company charges 18.00 per hour for labor.
- #include <iostream>
- #include <iomanip>
- using namespace std;
- // Prototype function
- int paintPerGallon();
- void roomPolicy();
- void validateRooms();
- // Global constant
- const double COMPANY_CHARGES = 18.00;
- // Main
- int main()
- {
- int numOfrooms;
- double totalSquareFeet = 0; // accumulator for running total
- double numOfGallons, hoursOfLabor;
- double costOfPaint, totalLabor;
- // Call function room policy for the user
- roomPolicy();
- // Ask user to enter number of rooms to be painted
- cout << "Enter the number of rooms to be painted.\n";
- cin >> numOfrooms;
- // Call function validate rooms for user.
- validateRooms();
- for (int loop = 1; loop <= numOfrooms; loop++)
- {
- int rooms;
- cout << "Enter the square feet for room " << loop << ":" << endl;
- cin >> rooms;
- totalSquareFeet += rooms;
- }
- // Format output
- cout << fixed << showpoint << setprecision(2);
- cout << "Total square feet is " << totalSquareFeet << "." << endl;
- paintPerGallon();
- numOfGallons = totalSquareFeet / 415;
- // Calculate hours of labor
- hoursOfLabor = numOfGallons * 8;
- // Calculate cost of paint
- costOfPaint = paintPerGallon * numOfGallons;
- // Calculate total labor
- totalLabor = hoursOfLabor * COMPANY_CHARGES;
- // Let the user know all totals from the paint job
- cout << "Total number of gallons used are " << numOfGallons << "." << endl;
- cout << "Total hours of labor are " << hoursOfLabor << "." << endl;
- cout << "The total cost of the paint is " << costOfPaint << "." << endl;
- cout << "Total labor charges will be " << totalLabor << "." << endl;
- return 0;
- }
- int paintPerGallon()
- {
- int paintPerGallon;
- cout << "How much is the paint per gallon?\n";
- cin >> paintPerGallon;
- if (paintPerGallon >= 10)
- return paintPerGallon;
- else
- cout << "That is too cheap for a gallon of paint! Please enter a valid price." << endl;
- }
- void roomPolicy()
- {
- cout << "Please be advised that we have a one room \n";
- cout << "minimum and a fifty room maximum rooms to be painted.\n";
- }
- void validateRooms()
- {
- int numOfrooms;
- while (numOfrooms < 1 || numOfrooms > 50)
- {
- cout << "Please see our room limit policy!\n";
- cin >> numOfrooms;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement