954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

items needed

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

timbomo
Junior Poster
122 posts since Feb 2010
Reputation Points: 3
Solved Threads: 0
 

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.

timbomo
Junior Poster
122 posts since Feb 2010
Reputation Points: 3
Solved Threads: 0
 

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
 
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?



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;
timbomo
Junior Poster
122 posts since Feb 2010
Reputation Points: 3
Solved Threads: 0
 

It seems to me you assume the user already knows the answers to all those values?

Some relations you might want to define are:

#define PAINT_PER_SQFT (1/500)
#define HOURS_PER_SQFT (8/500)

int myCeil(double d)
{
    return (int) d + 0.99;
}

int myRound(double d)
{
    return (int) d + 0.5;
}

int paintRequired(int area)
{
    return myCeil(PAINT_PER_SQFT * area);
}

int hoursRequired(int area)
{
    return myRound(HOURS_PER_SQFT * area);
}


And so on.. You should get the hang of it.

I hope this helps!
Emil Olofsson

emilo35
Junior Poster
103 posts since Feb 2010
Reputation Points: 14
Solved Threads: 12
 

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
 

what does the define mean in lines 1 and 2 ? and could you explain the return for me??

timbomo
Junior Poster
122 posts since Feb 2010
Reputation Points: 3
Solved Threads: 0
 
#define 'X' 'Y'


This is a pre compiler command, that tells the compiler to interpret all 'X' as 'Y'. This is a good way to define constants used in your program, and it really makes your code easier to understand.

Return points out what the return value of your function is.

In your case I strongly recommend looking for a beginners tutorial/book on C++. There is plenty of easy-to-understand literature online about trivial programming aspects such as how to use functions, operations, and how to plan and construct simple programs. Try google!

Emil Olofsson

emilo35
Junior Poster
103 posts since Feb 2010
Reputation Points: 14
Solved Threads: 12
 

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. here i used a switch statement i have more cases but i just copied and pasted the codes 2 each other case. if someone could give me a hint i could apply it to the rest of my cases.

do
    {
        cout << " How many rooms do you have " << endl;
        cin >> number_of_rooms;
           while ( number_of_rooms <= 1 )
                {
                cout << " Error, you must select more rooms " << endl;
                cout << " Please select number of rooms " << endl;
                cin >> number_of_rooms;
                }
        cout << " How many square feet " << endl;
 cout << " 1) 500 - 999 " << endl; /*if the user chooses this then its one gallon of paint*/
 cout << " 3) 1500 - 1900 " << endl;/*if the user chooses this then its two gallon of paint*/
 cout << " 4) 2000- 2500 " << endl;/*if the user chooses this then its three gallon of paint*/
 cin >> choice;                     /* the thing is i want to firgure out a way to compute any amount of 
                                    square feet staring with the minimum of 500sqft.*/
switch(choice)
{
case '1':
cout << " the paint required is one gallon " <<  endl;
 cout << " What is the hours of labor required " << endl;
        cin >> labor_required;
            while(labor_required<= 0)
            {
                cout << " You didnt work today or please put in a valid number of hours " << endl;
                cin >> labor_required;
                    while( labor_required <=0)
                        {
                            cout << " you know you didnt work, Y r u acting like you did " << endl;
                            return 0;
                        }
           }
        cout << " What is the cost of paint " << endl;
        cin >> cost_of_paint;
        while(cost_of_paint< 5 )
                {
                    cout << " Error, please enter the price per gallon of paint " << endl;
                    cin >> cost_of_paint;
                }
        cout << " what are the labor charges " << endl;
        labor_charge = (WAGE * labor_required);
        cin >> labor_charge;
        total_cost_of_paint = labor_charge * labor_required;
        cout << total_cost_of_paint;
        cout << " the number of rooms:   " << number_of_rooms << endl;
        cout << " Square footage :   " << square_footage << endl;
        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;
break;
timbomo
Junior Poster
122 posts since Feb 2010
Reputation Points: 3
Solved Threads: 0
 
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
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

am i putting these lines before int main()? and then i will call them when needed

#define PAINT_PER_SQFT (1/500)
#define HOURS_PER_SQFT (8/500)

int myCeil(double d)
{
    return (int) d + 0.99;
}

int myRound(double d)
{
    return (int) d + 0.5;
}

int paintRequired(int area)
{
    return myCeil(PAINT_PER_SQFT * area);
}

int hoursRequired(int area)
{
    return myRound(HOURS_PER_SQFT * area);
}
timbomo
Junior Poster
122 posts since Feb 2010
Reputation Points: 3
Solved Threads: 0
 

i know its hard to understand what i am trying to do :
You are to write a program that computes the cost of painting rooms. A painting company has determined that for every 500 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 per gallon of paint. It should then ask for the square feet of wall space in each room. Last, it must display the following:
• The number of gallons of paint required (rounded up).
• The hours of labor required.
• The cost of paint for the job.
• The labor charges.
• The total cost of the paint job.

Additional requirements:
• You must create functions to accept all data from the user. These functions must error trap for the following: number of rooms less than 1, price of paint less than $5.00 per gallon, and square footage less than 100 for any room.
• You must also create functions that calculate the hours of labor, the cost of labor and the cost of paint.
• Finally create one or more functions to display all of the results. Use two digits of precision for all non-integer numbers.
• Create global constants for all constant values (i.e. the 500 ft2, $18.00, and $5.00 mentioned above, plus any minimum number like number of rooms and square footage).

timbomo
Junior Poster
122 posts since Feb 2010
Reputation Points: 3
Solved Threads: 0
 

after the user states how many square feet they have, is there a better way 2 write this code other than using switch or if statements so if the user wants to say that they have 80000 sqft. and for every 500 sqft the user will need 1 gallon of paint. that will be alot of if statements.

if(sqft <=500 || sqft >=1000)
cout << " u need 1 gallon of paint " 
if (sqft <=1001 || sqft >= 1500)
cout << " u need 2 gallons of paint


"

instead of cout 'n u need 1 gallon i would like to just keep track of it and at the end display the number of gallons required corresponding to the square footage

timbomo
Junior Poster
122 posts since Feb 2010
Reputation Points: 3
Solved Threads: 0
 

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
 

when i do this formula i get 0 as my answer. Y is this???
#include
#include
using namespace std;
#define PAINT_PER_SQFT (1/500)
int main()

{
   int  squarefottage;
    double gallonneeded;
    cout << "what is the square fottage" << endl;
    cin >> squarefottage;
    gallonneeded = squarefottage * PAINT_PER_SQFT;
    cout << gallonneeded ;
return 0;
}
timbomo
Junior Poster
122 posts since Feb 2010
Reputation Points: 3
Solved Threads: 0
 

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
 

N/A

abhimanipal
Master Poster
742 posts since Dec 2009
Reputation Points: 114
Solved Threads: 104
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You