The program to calculate the total paint cost and other values is given below.
#include <iostream>
using namespace std;
int main() {
int rooms, laborChrg = 18;
float paintChrg;
float feetPerRoom[rooms];
float paintReq, laborHrs, paintCost, laborCost, totalCost, totalsqft=0;
cout<<"Enter the number of rooms to be painted "<<endl;
cin>>rooms;
for(int i=0; i <= rooms; i++)
{
cout<<"Enter the square feet in room "<<endl;
cin>>feetPerRoom[i];
// shortcut operator which is equivalent to totalsqft = totalsqft + feetPerRoom[i];
totalsqft += feetPerRoom[i];
}
cout<<"Enter the cost of the paint per gallon "<<endl;
cin>>paintChrg;
laborHrs = (totalsqft/115)*8;
laborCost = laborHrs * laborChrg;
paintReq = totalsqft/115;
paintCost = paintReq * paintChrg;
totalCost = laborCost + paintCost;
cout<<"The number of gallons of paint required "<<paintReq<<endl;
cout<<"The hours of labor required "<<laborHrs<<endl;
cout<<"The cost of the paint is "<<paintCost<<endl;
cout<<"The labor charges are "<<laborHrs<<endl;
cout<<"The Total cost of the paint job is "<<totalCost<<endl;
return 0;
}
Explanation:
The header files for input and output are imported.
#include <iostream>
using namespace std;
All the variables are taken as float except labour charge per hour and number of rooms.
The user is asked to input the number of rooms to be painted. An array holds the square feet in each room to be painted.
cout<<"Enter the number of rooms to be painted "<<endl;
cin>>rooms;
for(int i=0; i <= rooms; i++)
{
cout<<"Enter the square feet in room "<<endl;
cin>>feetPerRoom[i];
totalsqft += feetPerRoom[i];
}
The above code asks for square feet in each room and calculates the total square feet to be painted simultaneously.
All the data to be displayed is calculated based on the values of labor charge per hour and gallons of paint needed, given in the question.
laborHrs = (totalsqft/115)*8;
laborCost = laborHrs * laborChrg;
paintReq = totalsqft/115;
paintCost = paintReq * paintChrg;
totalCost = laborCost + paintCost;
All the calculated values are displayed in the mentioned order.