Need help...Easy fix but I can't figure it out.

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 18
Reputation: Nick6425fl is an unknown quantity at this point 
Solved Threads: 0
Nick6425fl Nick6425fl is offline Offline
Newbie Poster

Need help...Easy fix but I can't figure it out.

 
0
  #1
Nov 7th, 2008
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!

  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. void instructions();
  8.  
  9. double Paint(double, int);
  10.  
  11. double Labor(int);
  12.  
  13. double Total(double,double);
  14.  
  15. void Output(double, int, double, double);
  16.  
  17. main()
  18.  
  19. {
  20. int sqft;
  21.  
  22. double cpg, costlabor, costpaint, totalcost;
  23.  
  24. cout << showpoint << fixed << setprecision (2);
  25.  
  26. cout << "what is the square footage of the room? ";
  27. cin >> sqft;
  28. do
  29. {
  30. cout << "What is the cost per gallon of paint? ";
  31. cin >> cpg;
  32.  
  33. if(cpg<10.)
  34. cout << "Price must be at least $10.\n\n";
  35.  
  36. }
  37.  
  38. while(cpg<10);
  39.  
  40. costpaint=Paint(cpg, sqft);
  41.  
  42. costlabor=Labor(sqft);
  43.  
  44. totalcost=Total(costpaint, costlabor);
  45.  
  46. Output(totalcost, sqft, costpaint, costlabor);
  47.  
  48. }
  49.  
  50.  
  51. double Paint(double cpg, int sqft)
  52.  
  53. {
  54.  
  55. return ceil(sqft/115.)*cpg;
  56.  
  57. }
  58.  
  59. double Labor(int sqft)
  60. {
  61. return sqft/115.*(18.00*8);
  62. }
  63.  
  64. double Total(double paint,double labor)
  65. {
  66. return paint+labor;
  67. }
  68.  
  69. void Output(double total, int sqft, double paint, double labor)
  70.  
  71. {
  72. cout << "The number of gallons of paint required is ___\n";
  73. cout << "The hours of labor required is ___\n";
  74. cout << "The cost of the paint is $" << paint << endl;
  75. cout << "The labor charges are $" << labor << endl;
  76. cout << "The total cost of the paint job is $" << total << endl;
  77.  
  78. system("pause");
  79.  
  80. return;
  81. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,835
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Need help...Easy fix but I can't figure it out.

 
0
  #2
Nov 7th, 2008
  1. void Output(double total, int sqft, double paint, double labor)
  2.  
  3. {
  4. cout << "The number of gallons of paint required is ___\n";
  5. cout << "The hours of labor required is ___\n";
  6. cout << "The cost of the paint is $" << paint << endl;
  7. cout << "The labor charges are $" << labor << endl;
  8. cout << "The total cost of the paint job is $" << total << endl;
  9.  
  10. system("pause");
  11.  
  12. return;
  13. }

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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 182
Reputation: mrboolf will become famous soon enough mrboolf will become famous soon enough 
Solved Threads: 18
mrboolf mrboolf is offline Offline
Junior Poster

Re: Need help...Easy fix but I can't figure it out.

 
1
  #3
Nov 7th, 2008
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.
Last edited by mrboolf; Nov 7th, 2008 at 12:25 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 18
Reputation: Nick6425fl is an unknown quantity at this point 
Solved Threads: 0
Nick6425fl Nick6425fl is offline Offline
Newbie Poster

Re: Need help...Easy fix but I can't figure it out.

 
0
  #4
Nov 7th, 2008
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.
Last edited by Nick6425fl; Nov 7th, 2008 at 1:01 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 18
Reputation: Nick6425fl is an unknown quantity at this point 
Solved Threads: 0
Nick6425fl Nick6425fl is offline Offline
Newbie Poster

Re: Need help...Easy fix but I can't figure it out.

 
0
  #5
Nov 7th, 2008
Originally Posted by mrboolf View Post
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!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC