From 453902b44eae51909461df4081f32b905d8ccd7d Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Fri, 14 Oct 2022 12:41:10 +0100 Subject: [PATCH] w2 q2 --- main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index f75ac0e..35776cd 100644 --- a/main.cpp +++ b/main.cpp @@ -41,7 +41,11 @@ int main() { else printlm((v.at(static_cast(halfway - 1)) + v.at(static_cast(halfway))) / 2.0); double avg {}; - for (vtype i = 0; i < v.size(); ++i) avg += v.at(i); + if (v.size() > 2) { + for (vtype i = 1; i < v.size() - 1; ++i) avg += v.at(i); + } else { + for (vtype i = 0; i < v.size(); ++i) avg += v.at(i); + } avg /= static_cast(v.size()); printm("The average is: "); printlm(avg);