9618/21/M/J/25 question 3: worked solution (May/June 2025, paper 21)
Show as plain textHide plain text
Cambridge AS Level Computer Science 9618 · 11.2 Constructs Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3. Q59 9618/21/M/J/25 original Q3 Structured · 8 marks Worked solution Make the random number first. Then repeat: ask, check high, check low. Stop when the guess matches. DECLARE GeneratedValue : INTEGER DECLARE Guess : INTEGER GeneratedValue ← INT(RAND(100)) + 1 REPEAT OUTPUT "Enter a guess between 1 and 100: " INPUT Guess IF Guess > GeneratedValue THEN OUTPUT "Guess was too high" ENDIF IF Guess < GeneratedValue THEN OUTPUT "Guess was too low" ENDIF UNTIL Guess = GeneratedValue OUTPUT "Number guessed correctly" All variables declared [1] RAND() function used [1] INT() function used [1] Correct random number from 1 to 100: INT(RAND(100)) + 1 [1] Conditional loop that runs until the number is guessed [1] Prompt and input a guess inside the loop [1] Check if the guess is too high, with a message, inside the loop [1] Check if the guess is too low, with a message, inside the loop [1] The correct-guess message after the loop also scores. Any eight of the nine points get the 8 marks. KEY IDEA Generate the random number once, then loop with input and comparison until the guess equals it. TOTAL 8 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Sir Sikandar Raza. Tap the picture to open it on YouTube.