# Paint program

Status
Not open for further replies.

#### laserpp

##### Distinguished
Well here is the program first

Code:
``````Paint Job Estimation

#include <iostream>
using namespace std;

int numRooms();
int numGals(float);
float paintPrice(float);
float wallArea();
float laborHrs(float);
//void displayCost(int gallons, float paintPrice, float laborHrs);

int main()
{

float xprice = 0.3;
float gals = 0.1;
float xlabor = 0.2;

numRooms();
paintPrice(xprice);
wallArea();
numGals(gals);
laborHrs(xlabor);

return 0;
}

int numRooms()
{
int rooms;
cout << "Please enter the number of rooms: ";
cin >> rooms;

return rooms;

}

float paintPrice(float price)
{
cout << "Please enter the price per gallon: ";
cin >> price;

return price;
}

float wallArea()
{
float r1, r2, r3, r4, total;
cout << "Please enter the square feet of wall space for each room: " << endl;
cout << "Room 1: ";
cin >> r1;
cout << "Room 2: ";
cin >> r2;
cout << "Room 3: ";
cin >> r3;
cout << "Room 4: ";
cin >> r4;

total = r1 + r2 + r3 + r4;

}

int numGals(float gallons)
{
float total;

gallons = total / 160;
cout << "The number of gallons of paint required: " << gallons << " gallons" << endl;

return gallons;
}

float laborHrs(float labor)
{
float total;

labor = (total / 160) * 3;
cout << "The hours of labor required: " << labor << " hours" << endl;

return labor;

}``````
It isnt finished yet but working on it in pieces so I know what goes wrong when it does. My question is how do I get the total that I calculated from wall area into the other functions so I can do the math operations? I need the output of the program to be gallons of paint required, hours of labor, cost of paint, cost of labor and cost of job. For at least three of them I need to bring the total area of the wall into 3 other functions but it isnt working. Can I even do that?

#### kyeana

##### Distinguished
The wallArea() function returns a float, so all you would have to do is save that float when you call the function, and pass it in to any other functions that need it

Code:
``````float wallArea; // Create a float to hold the wallArea result
wallArea = wallArea(); // Save the value from wallArea() for future use
anotherFunction(wallArea); // Pass wallArea into another function, where it can be used.``````

#### kyeana

##### Distinguished
The wallArea() function returns a float, so all you would have to do is save that float when you call the function, and pass it in to any other functions that need it

Code:
``````float wallArea; // Create a float to hold the wallArea result
wallArea = wallArea(); // Save the value from wallArea() for future use
anotherFunction(wallArea); // Pass wallArea into another function, where it can be used.``````

#### laserpp

##### Distinguished
As you see in the wallArea() function I have total so could I do total = wallArea()? also do I put this in main? and like I want that total to go into numGals and laborHrs functions so should it be numGals(total) and laborHrs(total) instead of what I have there?

Code:
``````# int main()
# {
#
#     float xprice = 0.3;
#     float gals = 0.1;
#     float xlabor = 0.2;
#     float total;

total = wallArea();  // Should it be here? and should I get rid of the wallArea() below paintprice? bc wouldnt it run it twice in the program?

#     numRooms();
#     paintPrice(xprice);
#     wallArea();
#     numGals(total);
#     laborHrs(total);
#
#
#
#     return 0;
# }``````

#### laserpp

##### Distinguished
So I finished it and got it to work but it isn't as pretty as I could of made it but it works. Just confused why my teacher is making like a function a float and then making the parameters like an int? got a lot of errors about floats being turned into doubles and loss of data. Well here is the finished product.

Code:
``````//Jonathan Salina       Paint Job Estimation

#include <iostream>
using namespace std;

int numRooms();
int numGals(float);
float paintPrice(float);
float wallArea();
float laborHrs(float);
void displayCost(int, float, float);

int main()
{

float xprice = 0.3;
int job = 0;

numRooms();
float total = wallArea();
paintPrice(xprice);
float gallons = numGals(total);
float hours = laborHrs(total);
displayCost(job, gallons, hours);

return 0;
}

int numRooms()
{
int rooms;
cout << "Please enter the number of rooms: ";
cin >> rooms;

return rooms;

}

float paintPrice(float price)
{
cout << "Please enter the price per gallon: ";
cin >> price;

return price;
}

float wallArea()
{
float r1, r2, r3, r4, total;
cout << "Please enter the square feet of wall space for each room: " << endl;
cout << "Room 1: ";
cin >> r1;
cout << "Room 2: ";
cin >> r2;
cout << "Room 3: ";
cin >> r3;
cout << "Room 4: ";
cin >> r4;

total = r1 + r2 + r3 + r4;

}

int numGals(float gals)
{
float gallons;

gallons = gals / 160;
cout << "The number of gallons of paint required: " << gallons << " gallons" << endl;

return gallons;
}

float laborHrs(float hrs)
{
float labor;

labor = (hrs / 160) * 3;
cout << "The hours of labor required: " << labor << " hours" << endl;

return labor;

}

void displayCost(int job, float paint, float labor)
{

float paintCost;
float laborCost;
int jobCost;

paintCost = (paint * 25.50);
cout << "Total cost of paint: \$" << paintCost << endl;
laborCost = (labor * 28.00);
cout << "Total cost of labor: \$" << laborCost << endl;
jobCost = (paintCost + laborCost);
cout << "Total cost of job: \$" << jobCost << endl;
}``````

#### Mousemonkey

##### Distinguished
This topic has been closed by Mousemonkey

Status
Not open for further replies.
Apps General Discussion 8
Apps General Discussion 1
Apps General Discussion 1
Apps General Discussion 1
Apps General Discussion 0
Apps General Discussion 1
Apps General Discussion 2
Apps General Discussion 10
Apps General Discussion 2
Apps General Discussion 3
Apps General Discussion 2
Apps General Discussion 1
Apps General Discussion 3
Apps General Discussion 0
Apps General Discussion 8
Apps General Discussion 2
Apps General Discussion 14
Apps General Discussion 9
Apps General Discussion 3
Apps General Discussion 4