Paint program

Status
Not open for further replies.

laserpp

Distinguished
Nov 29, 2008
137
0
18,630
0
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;

		return total;
	}
	
	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
May 21, 2008
230
0
18,860
7
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
May 21, 2008
230
0
18,860
7
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
Nov 29, 2008
137
0
18,630
0
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
Nov 29, 2008
137
0
18,630
0
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;

		return total;
	}
	
	
	
	
	
	
	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;
	}
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
H Apps General Discussion 8
aymen9309 Apps General Discussion 1
SyndiShanX Apps General Discussion 1
D Apps General Discussion 1
BlueMoon1890 Apps General Discussion 0
Neon The (Anthro) Umbreon Apps General Discussion 1
K Apps General Discussion 2
T Apps General Discussion 10
M Apps General Discussion 2
R Apps General Discussion 3
S Apps General Discussion 2
N Apps General Discussion 1
kellysi Apps General Discussion 3
electro_neanderthal Apps General Discussion 0
A Apps General Discussion 8
G Apps General Discussion 2
K Apps General Discussion 14
B Apps General Discussion 9
L Apps General Discussion 3
woodenbear Apps General Discussion 4

ASK THE COMMUNITY