Im trying to figure out how i will calculate items needed.
for example for every 500 sqft of space, one gallon of paint and 8 hours of labor is required.
how will i put that n to a formula
The formula will depend on what you are trying to calculate and what you already know, so what are you trying to calculate and what do you already know?
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
im tryn 2 get
gallons of paint required (round up )
hours of labor required
cost of paint 4 da job
labor charges
total cost of paint job
and this is what i know
every 500 sqft of space is one gallon of paint and 8 hours of labor is required.
Then it's impossible. You need to know one or more values. All you know are ratios. You can't solve for all of the top 5 without knowing any of them or without knowing something that you haven't listed. Presumably you are supposed to ask for at least one of them as input, after which point you WILL know them and you can solve for the others. Which one(s)? And are you writing a computer program or is this a math problem?
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
o i got u i know wat u mean i didnt want 2 put the whole program on here but i will put a part on here to let you know wat im talkin bout
cout << " what is the number of gallons of paint required " << endl;
cin >> gallons_required;
cout << " What is the hours of labor required " << endl;
cin >> labor_required;
cout << " What is the cost of paint " << endl;
cin >> cost_of_paint;
cout << " what are the labor charges " << endl;
cin >> labor_charge;
cout << " what is the total cost of the paint job " << endl;
cin >> total_cost_of_paint;
cout << " gallons required : " << gallons_required << endl;
cout << " Labor required : " << labor_required << endl;
cout << " cost of paint : " << cost_of_paint << endl;
cout << " labor charge : " << labor_charge << endl;
cout << " total cost of job : " << total_cost_of_paint << endl;
Well then what are you trying to calculate? Everything you output is something that you have asked the user and they have told you. Usually you ask for the size of the room in square feet, the price per hour for labor, and the price per gallon for paint, and from that, you calculate the rest.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
i want to figure out a way other than a switch statement that will show the user how many gallons of paint are needed when the user says how many square feet they have.
If you don't want a switch statement, use a series of if statements.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
The math is square foot per room times 1 gallon of paint per 500 square feet. Then round that up to next int, which represents the number of gallons of paint to buy. Then multiply that int by cost of paint per gallon.
Rounding up in C++ can be fun. Let's say you 750 square feet to paint. that means you need 750 * (1/500) = 1.5 gallons, but you can't buy a partial gallon so you need to buy 2 gallons. How to round up? I can think of 3 ways to do it.
1) You could modulo the room size by 500 and if the result is zero, no rounding up is needed. Then divide the room size by 500 using the integer math that C++ uses and if no rounding is needed you have the gallons needed. If rounding is needed, then add 1 to the result. This allows you to do everything with ints.
2) You could use the ceil() function, which should return the next highest int if the input isn't an "even" number to begin with. This allows you to everything with type doubles/floats.
3) You could divide the square foot in room by 500 using type doubles, add .99999999999999999999999999999999999999999999... to the result and then cast the result to an int. For practical purposes this method works fine.
Let's say you go with version 1.
numGallons is roomSize divided by 500
if roomSize % 500 equals 0
then no rounding needed
else
round numGallons up by 1
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Beware of integer division:
#define PAINT_PER_SQFT (1/500)
Unless there is a reason, use doubles everywhere for all calculations. No need for rounding, ceiling, etc. You also have ceiling, floor, and other functions written for you in cmath. Unless there is a reason to write your own, use them. http://www.cplusplus.com/reference/clibrary/cmath/
You don't want if statements or switch statements. These are math formulas. You calculate the answers, then display the variables, not a hard-coded number for the amount of paint. Besides, your if statements are wrong anyway. You have to round UP, not, round off, and definitely not round down. If you have 501 square feet to paint and a bucket of paint can cover 500 square feet, then you are buying two buckets of paint:
double squareFeet = 501.0;
int numBuckets = (int) ceil (squareFeet / 500.0);
cout << "You need to buy " << numBuckets << " buckets of paint.";
Result:
You need to buy 2 buckets of paint.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
if(sqft <=500 || sqft >=1000)
cout << " u need 1 gallon of paint "
if (sqft <=1001 || sqft >= 1500)
cout << " u need 2 gallons of paint
"
Have you run this code? If I have am painting the entire Golden Gate Bridge and I need to cover a million square feet, according to this code, I can do it with one gallon of paint. But then I'll also need two gallons of paint, so I guess I should add 'em up and buy three, but I'm still happy since I though I was going to need more! :)
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
Read my post 16. I mention it there. (1/500) is 0. It's integer division so it truncates. If you want to divide and get 0.002, try changing it to:
(1.0 / 500.0)
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711