Getting weird output

I am writing a program using Eclipse for a class project. I am getting a strange output for my declared variable "fillGallons" at the end of the code. This part of the project is supposed to be calculating how many gallons of water the pool gains per hour given the fill rate of the user's hose (user entered). However, the output is always "1.61461e-316 gallons" no matter the number the user enters. When I do the math on my calculator, I don't get anything even close to this. I don't know what I'm doing wrong. I feel like it's something simple that I'm overlooking. Any help is 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
39
40
41
42
43
44
45
46
47
48
49
50
51
  #include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	// Variables
	double fill_rate;			// More than 0.5"/hr, no more than 2.25"/hr
	double poolLength = 40.0;	// In feet.
	double poolWidth = 20.0;	// In feet.
	double poolDepth = 6.0;		// In feet.
	double lengthInches = (poolLength * 12.0);
	double widthInches = (poolWidth * 12.0);
	double depthInches = (poolDepth * 12.0);
	double totalFeetVolume = (poolDepth * poolLength * poolWidth);
	double fillVolume = (poolLength * poolWidth * fill_rate) / 12.0; // In cubic feet
	double fillGallons = (fillVolume * 7.48);   // 7.48 gallons in a cubic foot
	double totalInchesVolume = (depthInches * widthInches * lengthInches);
	double inGallons = (lengthInches * widthInches * fill_rate) / 231;
	int counter = 0;
	const string fillMessage = "What is the fill rate of your hose in inches/hr.?";

	cout << fillMessage << endl;
	cin >> fill_rate;
	while (fill_rate < 0.5 || fill_rate > 2.25){
		cout << "ERROR. Your fill rate must be between 0.5 inches and\n"
			 << "2.25 inches. Please try again." << endl;
		cout << fillMessage << endl;
		cin >> fill_rate;
	}
	cout << "Great! You have a fantastic hose." << endl;
	cout << "Now, lets find out how many gallons of water your hose\n";
	cout << "puts in your pool every hour." << endl;
	cout << "Your pool is " << lengthInches << " inches long and " << widthInches << " \n";
	cout << "inches wide." << endl;
	cout << "You said your hose can produce " << fill_rate << " inches of water\n";
	cout << "every hour. The total volume of your pool is " << totalFeetVolume << " cubic\n";
	cout << "feet." << endl;
	cout << "That means that your pool is gaining " << fillGallons << " gallons\n";
	cout << "of water every hour." << endl;






	cin.get();
    return 0;
}
Last edited on
The problem lies on line 18 with fillVolume. The problem is you are multiplying poolLength and poolWidth to fill_rate which is unitiliazed which means it has a garbage value which would explain why it's giving a mumbo jumbo number.

Move fillVolume and fillGallons after you take in fill_rate then you should have a "normal" number.
Thank you so much! This fixed my problem.
Topic archived. No new replies allowed.