//Charlotte Davies-Kiernan CS1A Chapter 6 P. 374 #16
//
/******************************************************************************
*
* Compute Paint Job
* ____________________________________________________________________________
* This program uses the number of rooms to be painted, square feet of wall
* space in each room, and the price of the paint per gallon to then display
* the number of gallons of paint required, the hours of labor required, the
* cost of the paint, the labor charges, and the total cost of the paint job.
*
* Formulas Used:
* Gallons of paint required = (total square feet / square feet per gallon)
* Hours of labor required = (gallons * hours per gallon)
* Paint cost = gallons * paint price
* Labor cost = labor hours * labor rate
* Total cost = paint cost + labor cost
* ____________________________________________________________________________
* Input
* rooms //Number of rooms needed to be painted
* paintPrice //Price of paint per gallon
* totalSqFt //Total square feet amount that needs to be painted
* sqFt //Square feet per room
* sq_ft_per_gallon //Constant rate of square feet painted per gallon
* hours_per_gallon //Constant rate of labor per gallon
* laborRate //Constant hourly pay for labor
* Output
* gallons //Number of gallons of paint required
* laborHours //The hours of labor required
* paintCost //The cost of the paint
* laborCost //The labor charges
* totalCost //The total cost of the paint job
*****************************************************************************/
#include <iostream>
#include <iomanip>
#include <cmath> //For ceil
using namespace std;
//Global Constants
float sq_ft_per_gallon = 115.0;
float hours_per_gallon = 8.0;
float laborRate = 18.00;
//Function Prototypes
float calculateGallons(float totalSqFt);
float calculateLaborHours(float gallons);
float calculatePaintCost(float gallons, float paintPrice);
float calculateLaborCost(float laborHours);
void displayResults (float gallons, float laborHours, float paintCost, float laborCost, float totalCost);
int main() {
//Data Dictionary
float rooms; //INPUT - Number of rooms needed to be painted
float paintPrice; //INPUT - Price of paint per gallon
float totalSqFt; //INPUT - Total square feet amount that needs to be painted
float sqFt; //INPUT - Square feet per room
float gallons; //OUTPUT - Number of gallons of paint required
float laborHours; //OUTPUT - The hours of labor required
float paintCost; //OUTPUT - The cost of the paint
float laborCost; //OUTPUT - The labor charges
float totalCost; //OUTPUT - The total cost of the paint job
cout << fixed << setprecision(2);
cout << "Painting Company Cost Estimator: " << endl;
//Get User Input
cout << "Enter the number of rooms to be painted: " << endl;
cin >> rooms;
if (rooms < 1){
cout << "Please re-enter number of rooms (1 or more)" << endl;
cin >> rooms;
}
cout << "Enter the price of paint per gallon: $"<< endl;
cin >> paintPrice;
if (paintPrice < 10.00){
cout << "Invalid input, please enter a price more than $10.00" << endl;
cin >> paintPrice;
}
//Calculate Total Square Feet
totalSqFt = 0.0;
for (int i = 1; i <= rooms; i++){
cout << "Room " << i << endl;
cout << "Enter wall space (in square feet): " << endl;
cin >> sqFt;
if (sqFt < 0){
cout << "Invalid Measurement, please enter a non negative number: " << endl;
cin >> sqFt;
}
totalSqFt += sqFt;
}
//Calculations
gallons = calculateGallons(totalSqFt);
laborHours = calculateLaborHours(gallons);
paintCost = calculatePaintCost(gallons, paintPrice);
laborCost = calculateLaborCost(laborHours);
totalCost = paintCost + laborCost;
//Display Results
displayResults(gallons, laborHours, paintCost, laborCost, totalCost);
return 0;
}
float calculateGallons(float totalSqFt){
return ceil(totalSqFt / sq_ft_per_gallon); //ceil rounds up to the next whole gallon
}
float calculateLaborHours(float gallons){
return gallons * hours_per_gallon;
}
float calculatePaintCost(float gallons, float paintPrice){
return gallons * paintPrice;
}
float calculateLaborCost(float laborHours){
return laborHours * laborRate;
}
//Display Function
void displayResults(float gallons, float laborHours, float paintCost, float laborCost, float totalCost){
cout << "Paint Job Summary: " << 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;
}