Working out an average from a total and a count

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Working out an average from a total and a count

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly works out the average once Total and Count are known?
A Total <- Average / Count
B Average <- Total / Count
2. Where should Average <- Total / Count go in a loop that reads 10 marks?
A Inside the loop, before the last mark is read
B After the loop has ended
3. Which two statements belong inside the loop to build up the data for an average?
A Total <- Total + Mark and Count <- Count + 1
B Total <- Total / Count and Count <- Count + 1
4. Why check IF Count > 0 before working out the average?
A If Count is 0, dividing by it would cause an error
B If Count is 0, the average is always 100
5. Which is the safer way to calculate the average?
A IF Count > 0 THEN Average <- Total / Count ENDIF
B Average <- Total / Count IF Count > 0 THEN ENDIF

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Average <- Total / Count AChecks that at least one value was entered, so the program never divides by zero
2IF Count > 0 THEN BENDWHILE IF Count > 0 THEN Average <- Total / Count ENDIF
3Total and Count are both updated in the same loop, once for each value entered CThere is no check that Count is above 0. If the user enters no values, the program divides by zero. It needs IF Count > 0 THEN around the calculation.
4The average is calculated once, after the loop has ended, and only if Count is above 0 DThe average is calculated inside the loop, so it is recalculated every time instead of once at the end. It should come after ENDWHILE.
5WHILE Number <> -1 DO Total <- Total + Number Count <- Count + 1 Average <- Total / Count INPUT Number ENDWHILE EDivides the running total by the number of values to find the mean, after the loop has finished
6Average <- Total / Count OUTPUT Average FTotal <- Total + Number Count <- Count + 1

Definitions

Average <- Total / Count

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Average <- Total _ Count
2.
IF Count _ 0 THEN Average <- Total / Count ENDIF
3.
Total <- Total + Mark Count <- _____ + 1
4.
ENDWHILE IF Count > 0 ____ Average <- Total / Count
5.
Average <- Total / Count OUTPUT "Average: ", _______

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A IF Count >= 0 THEN
B Average <- Total / Count
C OUTPUT Average
D ENDIF
Question 2
A IF Count > 0 THEN
B Average <- Count / Total
C OUTPUT Average
D ELSE
E OUTPUT "No marks entered"
F ENDIF
Question 3
A REPEAT
B INPUT Mark
C Total <- Total + Mark
D Count <- Count + Mark
E UNTIL Count = 5
F Average <- Total / Count
Question 4
A Average <- 0
B IF Total > 0 THEN
C Average <- Total / Count
D ENDIF
E OUTPUT Average
Question 5
A FOR N <- 1 TO 4
B Total <- Total + Mark[N]
C Count <- 1
D NEXT N
E Average <- Total / Count

Answer Key

Working out an average from a total and a count
Section A: Quick Questions
Q1
B — Average <- Total / Count
Q2
B — After the loop has ended
Q3
A — Total <- Total + Mark and Count <- Count + 1
Q4
A — If Count is 0, dividing by it would cause an error
Q5
A — IF Count > 0 THEN Average <- Total / Count ENDIF
Section B: Match the Pairs
Q1
Average <- Total / Count → Divides the running total by the number of values to find the mean, after the loop has finished
Q2
IF Count > 0 THEN → Checks that at least one value was entered, so the program never divides by zero
Q3
Total and Count are both updated in the same loop, once for each value entered → Total <- Total + Number Count <- Count + 1
Q4
The average is calculated once, after the loop has ended, and only if Count is above 0 → ENDWHILE IF Count > 0 THEN Average <- Total / Count ENDIF
Q5
WHILE Number <> -1 DO Total <- Total + Number Count <- Count + 1 Average <- Total / Count INPUT Number ENDWHILE → The average is calculated inside the loop, so it is recalculated every time instead of once at the end. It should come after ENDWHILE.
Q6
Average <- Total / Count OUTPUT Average → There is no check that Count is above 0. If the user enters no values, the program divides by zero. It needs IF Count > 0 THEN around the calculation.
Section C: Definitions
Q1
Average <- Total / Count — After the loop ends, divide the total by the count to get the mean. Check that Count > 0 first, so the program never divides by zero.
Section D: Fill in the Blanks
Q1
Average <- Total / Count
Q2
IF Count > 0 THEN Average <- Total / Count ENDIF
Q3
Total <- Total + Mark Count <- Count + 1
Q4
ENDWHILE IF Count > 0 THEN Average <- Total / Count
Q5
Average <- Total / Count OUTPUT "Average: ", Average
Section E: Spot the Error
Q1
A — Count >= 0 is true when Count is 0, so the program would still divide by zero. The check must be IF Count > 0 THEN.
Q2
B — The average is the total divided by the count, not the other way round. It should be Average <- Total / Count.
Q3
D — Count must go up by 1 for each mark entered, not by the mark itself. It should be Count <- Count + 1.
Q4
B — The divisor is Count, so Count is the value that must be checked. Total > 0 does not stop a division by zero. It should be IF Count > 0 THEN.
Q5
C — Count <- 1 resets Count on every pass, so it always ends as 1 and the average is wrong. It should be Count <- Count + 1.