Structured programming and subroutines (procedures and functions)

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142
Question 21
Easy

The following pseudocode shows a subroutine designed to calculate the total sum of all below-freezing temperatures (temperatures less than 0) recorded in an array of daily temperatures.

SUBROUTINE calculateFreezingTotal(temps)
  p ← 0
  j ← 0
  WHILE j < LENGTH(temps)
    IF temps[j] < 0 THEN
      p ← p + temps[j]
    ENDIF
    j ← j + 1
  ENDWHILE
  RETURN p
ENDSUBROUTINE

The identifier for the variable p in the subroutine is not a good choice.

State a better identifier for this variable that makes the algorithm easier to read and understand.

[1]

Structured programming and subroutines (procedures and functions) Questions

  1. GCSE
  2. /Computer Science
  3. /Structured programming and subroutines (procedures and functions)