Help with program. Works but doesn't read from class file.

My int main works just fine however, when my program calls swimmingPool.h it closes and doesn't finish with the rest of the program. I do not have any errors or warnings being displayed when I debug my program.

I've included the code for the three files I am using for my program. Help would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//main program .cpp file

#include <iostream>
#include "swimmingPool.h"

using namespace std;

int main()
{
	//User input has a place to stay
	double length, width, depth;
	double rateWater, rateDrain;

	cout << "Pool Data\n" << endl;
	cout << "Length: ";
	cin >> length;
	cout << "Width: ";
	cin >> width;
	cout << "Depth: ";
	cin >> depth;
	cout << "Enter the rate in which water fills the pool: ";
	cin >> rateWater;
	cout << "Enter the rate in which water drains the pool: ";
	cin >> rateDrain;

	//Data from user gets stored into class. Then computes the info
	//into the algorithm which determines the time to drain the pool.
	swimmingPool poolInfo(length, width, depth, rateWater, rateDrain);
	double waterFill = poolInfo.poolWater();
	cout << "Time it will take to drain the pool: " << waterFill;

	//Takes the users data and determines how long it will
	//take to fill the pool.
	double timeToFillPool = poolInfo.timeToFill();
	cout << "Time it will take to fill the pool: " << timeToFillPool;

	return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//swimmingPool.h class file

#define GALLONS_IN_A_CUBIC_FEET 7.48;

class swimmingPool
{
public:
	swimmingPool();
	swimmingPool(double l, double w, double d, double rateFill, double rateDrain);
	double amountWaterNeeded();
	double timeToFill();
	double addWater(double time);
	double drainWater(double time);
	double poolWater();


private:
	double length;
	double width;
	double depth;
	double rateWaterFillsPool;
	double rateWaterDrainsPool;
};
	


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//swimmingPoolImp.cpp file that has all the algorithms

#include "swimmingPool.h"

swimmingPool::swimmingPool()
{
	//initializes the variables to 0. 
	length = 0;
	width = 0;
	depth = 0;
	rateWaterDrainsPool = 0;
	rateWaterFillsPool = 0;
}

	//Data from user(swimmingpool.h) gets categorized into specific varibles for easy computing
swimmingPool::swimmingPool(double l, double w, double d, double rateFill, double rateDrain)
{
	length = l;
	width = w;
	depth = d;
	rateWaterFillsPool = rateFill;
	rateWaterDrainsPool = rateDrain;
}
//Below are the algorithms for each specific request.
double swimmingPool::amountWaterNeeded()
{
	return (length * width * depth) * GALLONS_IN_A_CUBIC_FEET;
}
double swimmingPool::timeToFill()
{
	return poolWater() / rateWaterDrainsPool;
}
double swimmingPool::addWater(double time)
{
	return rateWaterDrainsPool * time;
}
double swimmingPool::drainWater(double time)
{
	return rateWaterDrainsPool * time;
}
double swimmingPool::poolWater()
{
	return (length*width*depth)*GALLONS_IN_A_CUBIC_FEET;
}


	
What os are you using, if windows, you probably have the console closing on its own
Windows 10. How would I make it to where it doesn't close by itself?
add cin.get(); before return 0;
Topic archived. No new replies allowed.