void readE(double & max, double & min, double & average)
{
double number, count = 0, sum = 0;
//max = 0; min = 0; average = 0;
cout << "Gimme #'s to do sum Math: ";
for (number; cin >> number; count++)
{
sum += number;
if (number > max)
max = number;
if (max>min)
min;
}
average = (sum / count);
recover();
if (count == 0) die("Input Failure");
cout << "The largest # seen is: " << max << endl;
cout << "The smallest # seen is: " << min << endl;
cout<<"The sum of the #'s seen is: " << average << endl;
}
To fix it, you'll need to either initialize min to a big number (say, std::numeric_limits<double>::max()) before the loop or put a if (count == 0) min = number; in your loop.
void readE(double & max, double & min, double & average)
{
double number, count = 0, sum = 0;
//max = -1e100; min = 1e100; average = 0;
cout << "Gimme #'s to do sum Math: ";
for (; cin >> number; count++)
{
if (count == 0)
{
min = number;
max = number;
}
sum += number;
if (number > max)
max = number;
if (number < min)
min = number;
}
average = (sum / count);
recover();
if (count == 0) die("Input Failure");
cout << "The largest # seen is: " << max << endl;
cout << "The smallest # seen is: " << min << endl;
cout<<"The sum of the #'s seen is: " << average << endl;
}
if (count == 0)
{
min = number;
max = number;
}
// ...
if (number < min)
min = number;
Those last two lines are essentially my first post:
I wrote:
Finding the minimum is the same as finding the maximum, just with the > flipped to a <.
The first few lines set the min and max to the number the user entered, but only on the first iteration of the loop (when count is 0).
That fixes the problem with min becoming 0 using my second suggestion:
I wrote:
To fix it, you'll need to either [...] or put a if (count == 0) min = number; in your loop.