// Timothy Price				CS1A				Ch6 Challenge 17
/*******************************************************************************
 * Calculate estimate
 * 
 * This program receives a number of rooms, a cost value of paint, and a square
 * footage value for each room, and calculates an estimate.
 * 
 * Inputs:
 *  Number of rooms
 *  Cost of paint
 *  Square feet per room
 * 
 * Outputs:
 *  Estimate for paint job
*******************************************************************************/

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

// Function prototypes
int get_rooms();
double get_paint();
double get_totalSqFt(int numRooms);
void job_details(double totalSqFt, double paintPrice);

// Call all functions to gather info and calculate estimate
int main() {
    int rooms = get_rooms();
    double paintPrice = get_paint();
    double totalSqFt = get_totalSqFt(rooms);

    job_details(totalSqFt, paintPrice);

    return 0;
}

// Gets and validates the number of rooms
int get_rooms() {
    int rooms;
    cout << "Enter the number of rooms to be painted: ";
    cin >> rooms;
    cout << rooms << " rooms." << endl;
    while (rooms < 1) {
        cout << "Error: Number of rooms must be 1 or greater." << endl;
        cout << "Enter the number of rooms to be painted: ";
        cin >> rooms;
    }
    return rooms;
}

// Gets and validates the price of paint per gallon
double get_paint() {
    double price;
    cout << "Enter the price of the paint per gallon ($): ";
    cin >> price;
    cout << fixed << setprecision(2);
    cout << "$" << price << endl;
    while (price < 10.00) {
        cout << "Error: Paint price cannot be less than $10.00." << endl;
        cout << "Enter the price of the paint per gallon ($): ";
        cin >> price;
    }
    return price;
}

// Asks for square footage of each room, validates it, and returns the total
double get_totalSqFt(int numRooms) {
    double totalSqFt = 0.0;
    double roomSqFt;

    for (int count = 1; count <= numRooms; count++) {
        cout << "Enter the square feet of wall space in room " << count << ": ";
        cin >> roomSqFt;
        cout << roomSqFt << " square feet." << endl;
        while (roomSqFt < 0) {
            cout << "Error: Square footage cannot be negative." << endl;
            cout << "Enter the square feet of wall space in room ";
            cout << count << ": ";
            cin >> roomSqFt;
        }
        totalSqFt += roomSqFt;
        
    }
    cout << totalSqFt << " total square feet." << endl;
    return totalSqFt;
}

// Calculates and displays the required paint, labor, and costs
void job_details(double totalSqFt, double paintPrice) {
    // 1 gal and 8 hrs labor per 115 square feet, as stated by challenge 
    double gallons = totalSqFt / 115.0;
    double laborHours = (totalSqFt / 115.0) * 8.0;
    double paintCost = gallons * paintPrice;
    double laborCharges = laborHours * 18.00;
    double totalCost = paintCost + laborCharges;

	// Display estimate
    cout << fixed << setprecision(2) << endl;
    cout << "------- Paint Job Estimate -------" << endl << endl;
    cout << "Gallons of paint required: " << gallons << endl;
    cout << "Hours of labor required:   " << laborHours << endl;
    cout << "Cost of the paint:         $" << paintCost << endl;
    cout << "Labor charges:             $" << laborCharges << endl;
    cout << "---------------------------------------" << endl;
    cout << "Total cost of the job:     $" << totalCost << endl;
}
