//Cameron Pham CS1A Chapter 6, p. 374, #17
//
/******************************************************************************
* ESTIMATE COST OF PAINT JOB
* ______________________________________________________________________________
* This program accepts floating values for number of rooms and cost of paint per
* gallon. It will then calculate the total cost of the paint job.
* ______________________________________________________________________________
* INPUT
* Rooms // Number of rooms that need to be painted
* Paint cost // Cost of paint per gallon
*
* OUTPUT
* Total cost // Total cost of paint job
*
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// Constant values
const double sqftPerGallon = 115.0;
const double hrsPerGallon = 8.0;
const double hourlyLaborRate = 18.00;
// Function prototypes
int getNumRooms();
double getPaintPrice();
double getWallSpace(int room);
double calculateGallons(double totalSquareFeet);
double calculateLaborHours(double gallons);
double calculatePaintCost(double gallons, double pricePerGallon);
double calculateLaborCost(double laborHours);
int main()
{
// Initialize variables
int rooms; // Number of rooms to paint
double paintPrice; // Price per gallon of paint
double wallSpace; // Wall space in each room
double totalSquareFeet = 0; // Total wall space
double gallons; // Gallons of paint required
double laborHours; // Hours of labor required
double paintCost; // Total cost of paint
double laborCost; // Total labor charges
double totalCost; // Total cost of the paint job
// Get the number of rooms and paint price
rooms = getNumRooms();
paintPrice = getPaintPrice();
// Get the wall space for each room
for (int room = 1; room <= rooms; room++)
{
wallSpace = getWallSpace(room);
totalSquareFeet += wallSpace;
}
// Calculate the paint and labor requirements
gallons = calculateGallons(totalSquareFeet);
laborHours = calculateLaborHours(gallons);
// Calculate the costs
paintCost = calculatePaintCost(gallons, paintPrice);
laborCost = calculateLaborCost(laborHours);
totalCost = paintCost + laborCost;
// Display the results
cout << fixed << setprecision(2);
cout << endl;
cout << "Gallons of paint required: " << gallons << endl;
cout << "Hours of labor required: " << laborHours << endl;
cout << "Cost of paint: $" << paintCost << endl;
cout << "Labor charges: $" << laborCost << endl;
cout << "Total cost of paint job: $" << totalCost << endl;
return 0;
}
// Ask for the number of rooms and validate the input
int getNumRooms()
{
int rooms;
cout << "Enter the number of rooms to be painted: ";
cin >> rooms;
cout << endl;
while (rooms < 1)
{
cout << "Please enter at least 1 room: ";
cin >> rooms;
}
return rooms;
}
// Ask for the price of paint per gallon and validate the input
double getPaintPrice()
{
double price;
cout << "Enter the price of paint per gallon (at least $10.00): $";
cin >> price;
cout << endl;
while (price < 10.00)
{
cout << "Price must be at least $10.00. Enter again: $";
cin >> price;
}
return price;
}
// Ask for the wall space in a room and validate the input
double getWallSpace(int room)
{
double squareFeet;
cout << "Enter the square feet of wall space in room "
<< room << ": ";
cin >> squareFeet;
cout << endl;
while (squareFeet < 0)
{
cout << "Square footage cannot be negative. Enter again: ";
cin >> squareFeet;
}
return squareFeet;
}
// Calculate gallons of paint needed, rounding up to a whole gallon
double calculateGallons(double totalSquareFeet)
{
return ceil(totalSquareFeet / sqftPerGallon);
}
// Calculate the labor hours required
double calculateLaborHours(double gallons)
{
return gallons * hrsPerGallon;
}
// Calculate the total cost of paint
double calculatePaintCost(double gallons, double pricePerGallon)
{
return gallons * pricePerGallon;
}
// Calculate the total labor charges
double calculateLaborCost(double laborHours)
{
return laborHours * hourlyLaborRate;
}