| | |
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:
Solved Threads: 0
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!
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)
#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; }
•
•
Join Date: Jan 2008
Posts: 3,835
Reputation:
Solved Threads: 503
C++ Syntax (Toggle Plain Text)
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.
•
•
Join Date: Jun 2008
Posts: 182
Reputation:
Solved Threads: 18
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.
•
•
Join Date: Nov 2008
Posts: 18
Reputation:
Solved Threads: 0
•
•
•
•
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.
![]() |
Similar Threads
- memory error (PHP)
- subject: SerializationStream message from hp Imaging (Windows NT / 2000 / XP)
- Dreamweaver CS3 Horizontal Spry dop down menu problem (Site Layout and Usability)
- Dreamweaver CS3 Horizontal Spry Menu Bar problem (Site Layout and Usability)
- svchost.exe - Windows Update - 100% CPU Utilization fix (EASY) (Windows NT / 2000 / XP)
- Need help; PC won't boot (Troubleshooting Dead Machines)
- Confused student, trying to figure out what career is right for him. (Computer Science)
- Javascript generated drop down menu (JavaScript / DHTML / AJAX)
- Please Help, Junk on machine (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Pointers, Arrays and Creating Objs...
- Next Thread: member data of a class
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






