// Illustrative teaching example, not a completed assessed submission.
// Compile: c++ -std=c++17 average-example.cpp -o average-example
#include <iostream>
#include <stdexcept>

double average(int total, int count) {
    if (count <= 0) {
        throw std::invalid_argument("count must be positive");
    }
    // Convert before dividing so the fractional part is retained.
    return static_cast<double>(total) / count;
}

int main() {
    std::cout << average(10, 3) << '\n'; // Expected: 3.33333
    try {
        average(10, 0);
        return 1; // A zero count must not be accepted.
    } catch (const std::invalid_argument& error) {
        std::cout << error.what() << '\n';
    }
}
