1 Replies - 350 Views - Last Post: 09 March 2009 - 03:52 AM Rate Topic: -----

#1 atlantis587  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 15-January 09

Still working with functions and have a small problem.

Posted 08 March 2009 - 10:48 PM

I've recently started working with functions.Whenever I run my program, all the numbers come out as whatever I entered in SFRoom.
I can't find the problem and I've been trying for while.
Any help is appreciated.

here's my program so far



#include<iostream>
#include<iomanip>
using namespace std;

//Function Prototypes
double gPaint(double &);
double hLabor(double);
double cPaint(double, double);
double laborC(double);
double total(double, double);

int main() {
	int		 numRooms;//Number of Rooms
	double	  paintRate,//Cost of paint per gallon
				sFRoom,//Square feet of room
				paintGall,//Gallons of paint needed
				laborHours,//Hours of labor needed
				paintCost,//The cost of paint for the job
				laborCost;//The cost of Labor for the job

	system("clear");
	cout << "\n\n\t\tWhat are the number of rooms that will be painted?: ";
	cin >> numRooms;

	cout << "\t\tWhat is the price of the paint per gallon?: ";
	cin >> paintRate;

	cout << "\t\tWhat is the square feet of wall space in each room?: ";
	cin >> sFRoom;

	paintGall = gPaint(sFRoom);
	laborHours = hLabor(sFRoom);
	paintCost = cPaint(paintGall, paintRate);
	laborCost = laborC(laborHours);

	cout << "\n\n\t\tWhat you will need\n"
		 << "\t\t-------------------------------------------------\n";
	cout << "\t\tGallons of Paint: " << paintGall << endl;
	cout << "\t\tHours of labor: " << laborHours << endl;
	cout << "\t\tCost of Paint: " << paintCost << endl;
	cout << "\t\tLabor Charges: " <<  laborCost << endl;
	cout << "\t\tTotal Charges: " << total(paintCost, laborCost) << endl;
	return 0;
}

double gPaint(double & SqFt) {
	SqFt / 115.0;
}

double hLabor(double SqFt) {
	(SqFt / 115.0) * 8.0;
}

double cPaint(double gallons, double rate) {
	gallons * rate;
}

double laborC(double hours) {
	hours * 18;
}

double total(double paint, double labor) {
	paint * labor;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Still working with functions and have a small problem.

#2 Sinister  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 26-January 09

Re: Still working with functions and have a small problem.

Posted 09 March 2009 - 03:52 AM

Your functions arnt returning any values and since u not using refference or pointers, the value of our "paintGall" and other variables wont change.

Instead of having

double hLabor(double SqFt) {
	(SqFt / 115.0) * 8.0;
}




try to change it to:

double hLabor(double SqFt) {
   return  ((SqFt / 115.0) * 8.0;) //To return the value of the calculation
}




Do all your functions like that.

Hope that helps.

This post has been edited by Sinister: 09 March 2009 - 04:23 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1