# Mean and Empty Data

- **Track:** Cambridge IGCSE™ Computer Science (0478 / 0984) (CAMBRIDGE IGCSE 0478)
- **Module:** Section 7: Algorithm Design & Problem-Solving
- **Estimated Duration:** 10 minutes
- **Access:** Open Theory (All-Access for Interactive IDE &amp; Autotests)

---

## Theory & Conceptual Background

The mean is total divided by count. The total and count must describe the same accepted values. Use real division because an average can have a fractional part.

## Worked trace

For readings 4,7,9: after 4, total=4 and count=1; after 7, total=11 and count=2; after 9, total=20 and count=3. The mean is 20/3, about 6.67. Dividing by the last value or by count-1 is incorrect.

If a sentinel arrives before any reading, count remains zero. Check count before dividing and provide an explicit no-data output. A sentinel terminates input; it is not another reading.

## Independent explanation

Explain why displaying zero as the average for no readings can be misleading: a genuine set of zero-valued readings has mean zero, whereas an empty set has no calculated mean.

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Independent Practice: Mean of readings (Pseudocode, 30 XP)

**Instructions:**
Read non-negative integer readings until -1. Output their mean rounded to two decimal places, or NO DATA if there are none.

Write a complete program. Read inputs in the stated order. Output only the requested results, one per line, without input prompts. Test with your own values before submitting.


**Starter Code:**
```text
// Plan your solution, then write your program.

```

**Autotest Expectations:**
- **Empty**: `test_case` -> Expected: `{&quot;inputs&quot;:[-1],&quot;output&quot;:&quot;NO DATA&quot;}`
- **Fractional**: `test_case` -> Expected: `{&quot;inputs&quot;:[4,7,9,-1],&quot;output&quot;:&quot;6.67&quot;}`
- **Actual zero**: `test_case` -> Expected: `{&quot;inputs&quot;:[0,0,-1],&quot;output&quot;:&quot;0&quot;}`

