3 ms·
There is a slight problem with one of the examples: void findMinMax(istream & input, double & min, double & max) // postcondition: min is the minimal valu
by nitrogen 16y ago
There is a slight problem with one of the examples:
void findMinMax(istream & input, double & min, double & max)
// postcondition: min is the minimal value in stream input,
// max is the maximal value in stream input
{
double min = DBL_MAX; // #include <float.h> for DBL_MAX
double max = DBL_MIN;
double current;
while (input >> current) {
if (current <= min) min = current;
if (current >= max) max = current;
}
}
The DBL_MIN should be -DBL_MAX if non-positive numbers should be found, as DBL_MIN is the positive double value closest to zero, not the most-negative double value.