943,723 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 775
  • C++ RSS
Nov 7th, 2008
0

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

Expand Post »
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!

C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nick6425fl is offline Offline
18 posts
since Nov 2008
Nov 7th, 2008
0

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

C++ Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Nov 7th, 2008
1

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

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.
Reputation Points: 134
Solved Threads: 18
Junior Poster
mrboolf is offline Offline
182 posts
since Jun 2008
Nov 7th, 2008
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nick6425fl is offline Offline
18 posts
since Nov 2008
Nov 7th, 2008
0

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

Click to Expand / Collapse  Quote originally posted by mrboolf ...
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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nick6425fl is offline Offline
18 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Pointers, Arrays and Creating Objs...
Next Thread in C++ Forum Timeline: member data of a class





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC