An algorithm has been written in pseudocode to allow some numbers to be input. All the positive numbers that are input are totalled and this total is output at the end. An input of 0 stops the algorithm. 01 Exit ← 1 02 WHILE Exit <> 0 DO 03 INPUT Number 04 IF Number < 0 05 THEN 06 Total ← Total + Number 07 ELSE 08 IF Number = 0 09 THEN 10 Exit ← 1 11 ENDIF 12 ENDIF 13 ENDIF 14 OUTPUT "The total value of your numbers is ", Number
- (a)Identify the four errors in the pseudocode and suggest a correction for each error. Error 1 Correction Error 2 Correction Error 3 Correction Error 4 Correction[4]
- (b)Describe how you could change the corrected algorithm to record and output how many positive numbers have been included in the final total. You do not need to rewrite the algorithm.[4]
Mark scheme
Marking points from the official mark scheme (May/June 2023). The mark or mark type is shown in brackets.
- [1] (a) Error 1: Line 04/ `IF Number < 0`. Correction: `IF Number > 0`
- [1] (a) Error 2: Line 10/ `Exit ← 1` when `Number = 0`. Correction: `Exit ← 0` (to stop the loop when Number = 0)
- [1] (a) Error 3: Line 13/`ENDIF`. Correction: `ENDWHILE`
- [1] (a) Error 4: Line 14 / `OUTPUT "The total value of your numbers is ", Number`. Correction: `OUTPUT "The total value of your numbers is ", Total`
- [1] (b) Initialise a new (counting) variable (e.g., Count)
- [1] (b) Assign initial value (e.g., `Count ← 0`)
- [1] (b) Insert a counting statement (e.g., `Count ← Count + 1`) within the `THEN` block (between lines 05 and 07) where positive numbers are processed
- [1] (b) Add a new output statement after the loop (after line 13) to display the Count (e.g., `OUTPUT Count`)
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →