Every time I run the program, using the exact same values (25 for diameter and 5 for depth), I am getting different values for water_price
and I'm not sure why.
Some of the outcomes:
$6.62256e+07 is the total cost.
$0 is the total cost.
$2.43411e-27 is the total cost.
I don't know if I am dealing with values in memory not playing well with each other, not flushing or what.
Why are the outcomes different every time I run this program?
#include <iostream>
#define PI 3.1416
#define WATER_COST 1.80
using std::cout;
using std::cin;
using std::endl;
int main() {
float pool_diameter, pool_depth;
float pool_radius = pool_diameter / 2;
float pool_volume_sq_inches = (PI * pool_radius * pool_radius * pool_depth) * 1728;
float pool_gallons = pool_volume_sq_inches / 231;
float water_price = (pool_gallons / 748) * WATER_COST;
cout << "Enter the pool diameter: ";
cin >> pool_diameter;
cout << "\nEnter the pool depth: ";
cin >> pool_depth;
cout << "\n$" << water_price << " is the total cost." << endl;
return 0;
}