Note AcademyNote Academy

Computer Science · May / June 2023 · Paper 21 · Question 5

0478

As printed in the paper

The question as text

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

Read automatically from the paper; the printed page above is exact.

Show the answer and mark scheme
  • 5(a)[4]

    One mark per mark point, max four

    Line 04 / IF Number < 0

    should be IF Number > 0

    Line 10 / Exit ← 1 // Line 01/ Exit ← 1 and Line 02 / WHILE Exit <> 0

    should be Exit ← 0 // should be Exit ← 0 and WHILE Exit = 0

    Line 13 / ENDIF

    should be ENDWHILE

    Line 14 / OUTPUT "The total value of your numbers is ", Number

    should be OUTPUT "The total value of your numbers is ", Total

    Correct 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 ← 0

    11 ENDIF

    12 ENDIF

    13 ENDWHILE

    14 OUTPUT "The total value of your numbers is ", Total

  • 5(b)[4]

    One mark per mark point, max four

    Initialise a new (counting) variable
    … Count ← 0 // to count the acceptable numbers
    Insert a counting statement between lines 05 and 07
    … Count ← Count + 1
    Add a new output after the loop/after line 13 / at the end (of the program)
    … OUTPUT Count

Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.