diff --git a/histogram.cpp b/histogram.cpp index 344f24d..d7e5196 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -5,14 +5,19 @@ using namespace std; void find_minmax(const vector &numbers, double &min, double &max){ - min = numbers[0]; - max = numbers[0]; - for (double x : numbers) { - if (x < min) { - min = x; - } - else if (x > max) { - max = x; + if (numbers.size() == 0){ + min = 0; + max = 0; + } else { + min = numbers[0]; + max = numbers[0]; + for (double x : numbers) { + if (x < min) { + min = x; + } + else if (x > max) { + max = x; + } } } } diff --git a/histogram_internal.h b/histogram_internal.h index 3ea054e..630e711 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -3,6 +3,6 @@ #include -void find_minmax(const std::vector &numbers, double &min, double &max) +void find_minmax(const std::vector &numbers, double &min, double &max); #endif // HISTOGRAM_INTERNAL_H_INCLUDED