Practice

Rounded Average of a Value List

2024/May/June·Variant 2
EASYLoops

A program must read a number of values (between 1 and 20) and then that many integers, calculating their total and average.

Validate the count with a loop that rejects anything outside 1 to 20. Output the total, then the average rounded to 1 decimal place.

Input: A count (validated 1–20), then that many integers. Output: Total: <total> then Average: <average to 1 dp>.

Example:

Input:  5
        10
        20
        30
        40
        50
Output: Total: 150
        Average: 30
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Five values, whole-number average
Inputs: 5, 10, 20, 30, 40, 50
Expected: Total: 150 Average: 30
Test 2: Average rounds to one decimal place
Inputs: 3, 1, 2, 2
Expected: Total: 5 Average: 1.7