Totalling: how it works

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

Totalling: how it works

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Where should Total be set to 0 in a totalling algorithm?
A Inside the loop on every repeat
B Before the loop starts
2. Which line adds each new Value to the running total?
A Total ← Total + Value
B Total ← Value
3. Where should OUTPUT Total go to show the final sum?
A After the loop has finished
B Inside the loop, before any values are added
4. What is the starting value of Total in a totalling algorithm?
A 0
B 1
5. Which line is used for counting rather than totalling?
A Total ← Total + Value
B Count ← Count + 1

Match the Pairs

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

Left columnRight column
1Total ← 0 ATotal is set to 0 inside the loop, so it is reset every time round and the running sum is lost. It should be set to 0 once before the loop.
2Total ← Total + Value BSets the running total to zero before the loop starts, so the sum begins from nothing
3Totalling adds the value itself each time, but counting adds 1 each time CAdds the current value to the running total inside the loop
4The total is output once after the loop has finished, not inside it DENDFOR OUTPUT Total
5FOR Index ← 1 TO 5 Total ← 0 Total ← Total + Value NEXT Index EThis adds 1 each time, which is counting, not totalling. It should add the value: Total ← Total + Value.
6FOR Index ← 1 TO 5 Total ← Total + 1 NEXT Index FCount ← Count + 1

Definitions

Total ← Total + Value

Fill in the Blanks

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

1.
Total ← _ FOR Index ← 1 TO 5 INPUT Value
2.
FOR Index ← 1 TO 5 INPUT Value Total ← _____ + Value
3.
Total ← Total + Value NEXT Index ______ Total
4.
FOR Index ← 1 TO 5 INPUT Value Count ← Count + _
5.
FOR Index ← 1 TO 5 INPUT Value Total ← Total _ Value

Spot the Error

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

Question 1
A DECLARE Total : INTEGER
B Total ← 1
C FOR N ← 1 TO 4
D Total ← Total + Mark[N]
E NEXT N
F OUTPUT Total
Question 2
A Total ← Score[1]
B FOR N ← 1 TO 5
C Total ← Total + Score[N]
D NEXT N
E OUTPUT Total
Question 3
A Total ← 0
B FOR N ← 1 TO 5
C Total ← Price[N]
D NEXT N
E OUTPUT Total
Question 4
A Total ← 0
B FOR N ← 2 TO 4
C Total ← Total + Mark[N]
D NEXT N
E OUTPUT Total
Question 5
A DECLARE Total : STRING
B Total ← 0
C FOR N ← 1 TO 5
D Total ← Total + Cost[N]
E NEXT N
F OUTPUT Total

Answer Key

Totalling: how it works
Section A: Quick Questions
Q1
B — Before the loop starts
Q2
A — Total ← Total + Value
Q3
A — After the loop has finished
Q4
A — 0
Q5
B — Count ← Count + 1
Section B: Match the Pairs
Q1
Total ← 0 → Sets the running total to zero before the loop starts, so the sum begins from nothing
Q2
Total ← Total + Value → Adds the current value to the running total inside the loop
Q3
Totalling adds the value itself each time, but counting adds 1 each time → Count ← Count + 1
Q4
The total is output once after the loop has finished, not inside it → ENDFOR OUTPUT Total
Q5
FOR Index ← 1 TO 5 Total ← 0 Total ← Total + Value NEXT Index → Total is set to 0 inside the loop, so it is reset every time round and the running sum is lost. It should be set to 0 once before the loop.
Q6
FOR Index ← 1 TO 5 Total ← Total + 1 NEXT Index → This adds 1 each time, which is counting, not totalling. It should add the value: Total ← Total + Value.
Section C: Definitions
Q1
Total ← Total + Value — Totalling keeps a running sum. Set Total to 0 before the loop, add each Value to Total inside the loop, then output Total after the loop. Counting adds 1 each time instead of the value.
Section D: Fill in the Blanks
Q1
Total ← 0 FOR Index ← 1 TO 5 INPUT Value
Q2
FOR Index ← 1 TO 5 INPUT Value Total ← Total + Value
Q3
Total ← Total + Value NEXT Index OUTPUT Total
Q4
FOR Index ← 1 TO 5 INPUT Value Count ← Count + 1
Q5
FOR Index ← 1 TO 5 INPUT Value Total ← Total + Value
Section E: Spot the Error
Q1
B — A running total must start at 0. Starting at 1 makes the final answer 1 too high. It should be Total ← 0.
Q2
A — Total must be set to 0 before the loop. Starting with Score[1] means the first score is added twice. It should be Total ← 0.
Q3
C — This replaces Total each time instead of adding to it, so only the last price is kept. It should be Total ← Total + Price[N].
Q4
B — The loop starts at 2, so Mark[1] is never added to the total. It should be FOR N ← 1 TO 4.
Q5
A — A total is a number that values are added to, so it cannot be a STRING. It should be DECLARE Total : INTEGER (or REAL).