Ready to begin
No records have been processed. Start with Next step.
We want the students whose Mathematics mark is below the average of the whole class. A running average changes whenever another card is read. Deciding permanently from that unfinished average can give the wrong answer.

Read the current record, check the explanation, and watch the variables. Use Back to revisit any step.
Ready
No records have been processed. Start with Next step.
Start at the first step. Watch the current row and the values we remember.
Sum = 0
Count = 0
for each row X in Scores {
Sum = Sum + X.Mathematics
Count = Count + 1
}
if (Count == 0) { report "No average"; stop }
Average = Sum / Count
for each row X in Scores {
if (X.Mathematics < Average) { record X.CardNo }
}Our 30 cards sum to 2,171, so the exact average is 2171/30 ≈ 72.3667. For integer marks, 72 is below this average and 73 is above it. Compare with the unrounded average, even when the display is rounded.
| Meaning | Result |
|---|---|
| Below-average IDs | 0, 1, 2, 3, 5, 9, 10, 12, 13, 17, 18, 19, 22, 24, 29 |
| Number below average | 15 |
| Visits for two full passes | 30 + 30 = 60 |
The first loop ends before the second begins. We do not scan all 30 cards again inside each visit. Both passes may read the data without changing it; with physical piles, restore the cards before pass 2.
For the tiny example 50, 50, 50, 100, the average is 62.5 and three of four values are below it. If all values are equal, none is strictly below average. The result 15 out of 30 is a property of our supplied marks, not a general law.
Why can a running average misclassify an earlier card?
A later value can move the average up or down. An earlier value may cross the new threshold.
Does a Mathematics mark of 72 pass the below-average test here?
Yes. 72 < 2171/30.
Are the two loops one inside the other?
No. They run sequentially: finish pass 1, then start pass 2.
What if Count is zero?
Do not divide by zero. Report that there is no average.
How many of 50,50,50,100 lie below their mean?
Three. Their mean is 62.5.