 Hey guys,
I'm working on my homework assignment and I did all the code, but I can't figure out how to display the "hours of labor required" and The number of gallons of paint required.

Here is the assignment:

A painting company has determined that for every 115 square feet of wall space, one
gallon of paint and eight hours of labor will be required. The company charges
\$18.00 per hour for labor. Write a modular program that allows the user to enter the
number of rooms that are to be painted and the price of the paint per gallon. It should
also ask for the square feet of wall space in each room. It should then display the fol-
lowing data:
• The number of gallons of paint required
• The hours of labor required
• The cost of the paint
• The labor charges
• The total cost of the paint job
Input validation: Do not accept a value less than 1 for the number of rooms. Do not
accept a value less than \$10.00 for the price of paint. Do not accept a negative value
for square footage of wall space.

Any help would be great!

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

using namespace std;

void instructions();

double Paint(double, int);

double Labor(int);

double Total(double,double);

void Output(double, int, double, double);

main()

{
int sqft;

double cpg, costlabor, costpaint, totalcost;

cout << showpoint << fixed << setprecision (2);

cout << "what is the square footage of the room? ";
cin >> sqft;
do
{
cout << "What is the cost per gallon of paint? ";
cin >> cpg;

if(cpg<10.)
cout << "Price must be at least \$10.\n\n";

}

while(cpg<10);

costpaint=Paint(cpg, sqft);

costlabor=Labor(sqft);

totalcost=Total(costpaint, costlabor);

Output(totalcost, sqft, costpaint, costlabor);

}

double Paint(double cpg, int sqft)

{

return ceil(sqft/115.)*cpg;

}

double Labor(int sqft)
{
return sqft/115.*(18.00*8);
}

double Total(double paint,double labor)
{
return paint+labor;
}

void Output(double total, int sqft, double paint, double labor)

{
cout << "The number of gallons of paint required is ___\n";
cout << "The hours of labor required is ___\n";
cout << "The cost of the paint is \$" << paint << endl;
cout << "The labor charges are \$" << labor << endl;
cout << "The total cost of the paint job is \$" << total << endl;

system("pause");

return;
}``````

## All 4 Replies

``````void Output(double total, int sqft, double paint, double labor)

{
cout << "The number of gallons of paint required is ___\n";
cout << "The hours of labor required is ___\n";
cout << "The cost of the paint is \$" << paint << endl;
cout << "The labor charges are \$" << labor << endl;
cout << "The total cost of the paint job is \$" << total << endl;

system("pause");

return;
}``````

Well, you need a variable that represents the number of gallons of paint and you need one that represents the number of hours of labor. You can't display something that hasn't been passed to the function. I would change the variable names to make them more descriptive. paint, labor, and total could be made more descriptive by calling them paintCost, laborCost, totalCost. A reader doesn't know whether paint refers to the cost of the paint or the number of gallons of paint. Ditto with labor. Naming the variables more descriptively will help you debug too because you can forget what they mean too, just like the reader. So you need variables called laborHours and paintGallons, or similar, and you need to pass them to the function. You pass the variable sqft, but don't use it. What does it represent? Again, more descriptive variable names will help you. And if you don't use a variable (like sqft), don't pass it to the function.

`return ceil(sqft/115.)*cpg;` here's your total paint cost. Divide by cost per gallon and you will obtain the number of gallons used Oo (read: do not multiply for cpg).

It's the same for the number of hours required: `sqft/115.*(18.00*8)` gives you the cost of the whole labor. Divide it by the cost-per-hour and you have it...

EDIT: As VernonDozier already suggested if you want to print all the info in your output function you should pass'em to it.

commented: Great Help! +1 Thank you mrboolf!!!...I'll try what you said and reply if I have trouble. I don't know why but I have the hardest time passing to the function. `return ceil(sqft/115.)*cpg;` here's your total paint cost. Divide by cost per gallon and you will obtain the number of gallons used Oo (read: do not multiply for cpg).

It's the same for the number of hours required: `sqft/115.*(18.00*8)` gives you the cost of the whole labor. Divide it by the cost-per-hour and you have it...

EDIT: As VernonDozier already suggested if you want to print all the info in your output function you should pass'em to it.

IT works!!!! Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.