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

Recommended Answers

All 27 Replies

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?

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.

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?

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;

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

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.

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

#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

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;

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.

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);
}

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).

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

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

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.
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! :)

when i do this formula i get 0 as my answer. Y is this???
#include<iostream>
#include<cmath>
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;
}

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)

N/A

i can get this to round up can anyone help? i have been using the ceil function but its not working right i get an error saying it cant be used as a function.
i put ceil b4 the ( in this formula below and i put ceil b4 the ( in the 2nd formula.

tot_gallon = (square_footage*(1.0/500.0));
        cout << " The number of gallons of paint that are needed to paint " << endl;
        cout << square_footage << " square feet is:_______ " << (tot_gallon) << endl;
        cout << "\n";
        hour_labor = (square_footage*(8.0/500.0));
        cout << " the numbers of hours of work required to paint " << endl;
        cout << square_footage << " square feet is: ______ " << (hour_labor) << endl;
        cout << " \n";

Have you included math.h ?
Can you post the code where you have actually used the ceil function

i can get this to round up can anyone help? i have been using the ceil function but its not working right i get an error saying it cant be used as a function.
i put ceil b4 the ( in this formula below and i put ceil b4 the ( in the 2nd formula.

Are you unable to post the exact error? What does "not working right" mean? Why can't ceil be used?

You should know by now it's a waste of time to post questions without details because we just ask questions about stuff you didn't tell us. Then we have to wait for you. Hours and many posts later, you get an answer. Cut that time by figuring out what might help us understand and just explain the entire problem in one post. Errors and all.

o sorry, but i want it to round up, i have used cmath and math.h and it still says :

error: `ceil' cannot be used as a function

code:

    while( square_footage <= 100 )
            {
                cout << " Error, you must select more rooms " << endl;
                cout << " Please type a number greater than 100 " << endl;
                cin >> square_footage;
            }
    cout << "\n";
    tot_gallon = ceil(square_footage*(1.0/500.0));
    cout << " The number of gallons of paint that are needed to paint " << endl;
    cout << square_footage << " square feet is:_______ " << (tot_gallon) << endl;
    cout << "\n";
    hour_labor = ceil(square_footage*(8.0/500.0));
    cout << " the numbers of hours of work required to paint " << endl;
    cout << square_footage << " square feet is: ______ " << (hour_labor) << endl;

What compiler?

Why not just do your own ceil() function? hour_labor = (int)(square_footage*(8.0/500.0)) + 1;

What compiler?

Why not just do your own ceil() function? hour_labor = (int)(square_footage*(8.0/500.0)) + 1;

ok y did you put (int) there, i did not know you could do that. thats why i like this forum cuz when i am writing a program i got an idea of wat to do but i allways second guess myself b/c idk if i can do that but the experts like yourself and others show me somethen new

but here is my program im done tell me wat u think

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
const double WAGE=18.00;
int main()
{
    double cost_of_paint,total_cost_of_paint, tot_gallon, hour_labor, tot_cost, labor_charge;
    int number_of_rooms, square_footage,;

    cout  <<  " Welcome to the Paint Shop " << setw(15) << endl << endl;

    do
    {
        cout << " How many rooms do you have to paint, please type a number 1 or greater:______ ";
        cin >> number_of_rooms;
        cout << "\n";
           while ( number_of_rooms <= 1 )
                {
                cout << " Error, you must select more rooms " << endl;
                cout << " Please type the number of rooms you want painted";
                cin >> number_of_rooms;
                }
        cout << " What is the cost of paint? :________ ";
        cin >> cost_of_paint;
        cout << "\n";
        while(cost_of_paint< 5 )
                {
                    cout << " Error, the price of paint must be greater than 5, please type the right number " << endl;
                    cin >> cost_of_paint;
                }
        cout << "\n";
        cout << " How many square feet do you want to be painted " << endl;
        cout << " please type a number the minumum is 500 square feet:______  ";
        cin >> square_footage;
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);
        cout << "\n";
            while( square_footage <= 100 )
                {
                    cout << " Error, you must select more rooms " << endl;
                    cout << " Please type a number greater than 100 " << endl;
                    cin >> square_footage;
                }
        cout << "\n";
        tot_gallon = (int)(square_footage*(1.0/500.0) + 1);
        cout << " The number of gallons of paint that are needed to paint " << endl;
        cout << square_footage << " square feet is:_______ " << (tot_gallon) << endl;
        cout << "\n";
        hour_labor = (square_footage*(8.0/500.0));
        cout << " the numbers of hours of work required to paint " << endl;
        cout << square_footage << " square feet is: ______ " << (hour_labor) << endl;
        cout << " \n";

        {
        cout << "################################################################### " << endl;
        cout << "\n";
        cout << " the number of rooms:   " << setw(17) << number_of_rooms << endl;
        cout << " Square footage :   " << setw(23) << square_footage << endl;
        cout << " The charge per hour is:  " << setw(19) << WAGE << " hours " << endl;
        cout << " cost of paint :   " << setw(25) << cost_of_paint << " dollars " << endl;
        labor_charge =( WAGE * hour_labor);
        cout << " labor charge :   " << setw(28) << labor_charge << " dollars " << endl;
        cout << " total gallons of paint: " << setw(19)  << tot_gallon << endl;
        cout << " The number of hours requried:  " << setw(12) << hour_labor << endl;
        tot_cost = (WAGE * hour_labor * cost_of_paint);
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);
        cout << "\n";
        cout << " the total cost of paint job is: " << endl << endl;
        cout << "\n" <<setw(46) << tot_cost << " dollars " << endl << endl;
        cout << "######################################################################### " << endl;
        }
    }while (number_of_rooms <=1);
return 0;
}

It's too busy. Too much output peppered throughout the code.
75 lines of code -- 40 cout statements, 6 cin statements. But it's all jumbled together. Can't see the program for the output.

Make some functions to input values, do calculations, output values. It will make the main function small and concise, and each function will be easier to read and the program flows better. And moves the output statements into modules which gets them out of the way.

It's too busy. Too much output peppered throughout the code.
75 lines of code -- 40 cout statements, 6 cin statements. But it's all jumbled together. Can't see the program for the output.

Make some functions to input values, do calculations, output values. It will make the main function small and concise, and each function will be easier to read and the program flows better. And moves the output statements into modules which gets them out of the way.

well its a basic program and i moved it to like 60 lines now and a few of those lines are just brackets.

#include<iostream>
#include<iomanip>
using namespace std;
const double WAGE=18.00;
int main()
{
    double cost_of_paint,total_cost_of_paint, tot_gallon, hour_labor, tot_cost, labor_charge;
    int number_of_rooms, square_footage,;
    cout  <<  " Welcome to the Paint Shop " << setw(15) << endl << endl;
    do
    {
        cout << " How many rooms do you have to paint, please type a number 1 or greater: ";
        cin >> number_of_rooms;
           while ( number_of_rooms <= 1 )
                {
                cout << " Error, you must select more rooms, number of rooms? ";
                cin >> number_of_rooms;
                }
        cout << " What is the cost of paint? : ";
        cin >> cost_of_paint;
            while(cost_of_paint< 5 )
                {
                    cout << " Error, the price of paint must be greater than 5, please type the right number " << endl;
                    cin >> cost_of_paint;
                }
        cout << " How many square feet do you want to be painted, 500 is the minimum: ";
        cin >> square_footage;
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);
            while( square_footage <= 100 )
                {
                    cout << " Please type a number greater than 100 " << endl;
                    cin >> square_footage;
                }
        tot_gallon = (int)(square_footage*(1.0/500.0) + 1);
        cout << " The number of gallons of paint that are needed to paint: " << tot_gallon;
        hour_labor = (square_footage*(8.0/500.0));
        cout << " the numbers of hours of work required to paint: " << hour_labor;
        {
        cout << "################################################################### " << endl;
        cout << " the number of rooms:   " << setw(17) << number_of_rooms << endl;
        cout << " Square footage :   " << setw(23) << square_footage << endl;
        cout << " The charge per hour is:  " << setw(19) << WAGE << " hours " << endl;
        cout << " cost of paint :   " << setw(25) << cost_of_paint << " dollars " << endl;
        labor_charge =( WAGE * hour_labor);
        cout << " labor charge :   " << setw(28) << labor_charge << " dollars " << endl;
        cout << " total gallons of paint: " << setw(19)  << tot_gallon << endl;
        cout << " The number of hours requried:  " << setw(12) << hour_labor << endl;
        tot_cost = (WAGE * hour_labor * cost_of_paint);
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);
        cout << " the total cost of paint job is: " << setw(40) << tot_cost << " dollars" << endl;
        cout << "######################################################################### ";
        }
    }while (number_of_rooms <=1);
return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.