Skip to content

9618 · 11.2

Constructs — practice questions

Practice and worked examples for 9618 Constructs. Short previews only — attempt the full question in MarkScheme against the official scheme.

Worked example 1

A cinema charges for tickets based on age. Ages 12 and under pay £6. Ages 13 to 17 pay £8. Ages 18 to 64 pay £12. Seniors (65+) pay £7. Write a pseudocode algorithm that takes an age as input and outputs the correct ticket price.

Show solution outline

This problem requires checking an age against several ranges, making it a perfect candidate for a chained IF...THEN...ELSEIF structure.

DECLARE Age : INTEGER
DECLARE Price : REAL

OUTPUT "Please enter your age: "
INPUT Age

IF Age <= 12 THEN
  Price <- 6.00
ELSEIF Age >= 13 AND Age <= 17 THEN
  Price <- 8.00
ELSEIF Age >= 18 AND Age <= 64 THEN
  Price <- 12.00
ELSE  // This covers ages 65 and over
  Price <- 7.00
ENDIF

OUTPUT "The ticket price is: £", Price

Marking Points:

  1. Correctly declaring variables (Age, Price).
  2. Prompting for and inputting the age.
  3. Correct use of IF...ELSEIF...ELSE...ENDIF structure.
  4. Correct conditions for each age bracket.
  5. Assigning the correct price for each case.
  6. Outputting the final calculated price.

Worked example 2

Write a pseudocode algorithm that calculates the average of a set of positive scores entered by a user. The user will enter -1 to signify they have finished entering scores. The program should not include the -1 in the calculation.

Show solution outline

Since we don't know how many scores the user will enter, a condition-controlled loop is needed. A WHILE loop is a good choice because we need to check the input value before processing it.

DECLARE Score, Total, Count : INTEGER
DECLARE Average : REAL

Total <- 0
Count <- 0

OUTPUT "Enter a score (or -1 to finish): "
INPUT Score

WHILE Score <> -1 DO
  Total <- Total + Score
  Count <- Count + 1
  OUTPUT "Enter next score (or -1 to finish): "
  INPUT Score
ENDWHILE

IF Count > 0 THEN
  Average <- Total / Count
  OUTPUT "The average score is: ", Average
ELSE
  OUTPUT "No scores were entered."
ENDIF

Marking Points:

  1. Initialisation of Total and Count to 0.
  2. Priming read: Inputting the first score before the loop.
  3. Correct WHILE loop condition (Score<>1Score <> -1).
  4. Correctly updating Total and Count inside the loop.
  5. Inputting the next score at the end of the loop body.
  6. Correctly closing the loop with ENDWHILE.
  7. Checking for division by zero (IFCount>0IF Count > 0) before calculating the average.