Photo AI

A number matching game stores four winning numbers and compares them to a player's input of four numbers - Scottish Highers Computing Science - Question 8 - 2023

Question icon

Question 8

A-number-matching-game-stores-four-winning-numbers-and-compares-them-to-a-player's-input-of-four-numbers-Scottish Highers Computing Science-Question 8-2023.png

A number matching game stores four winning numbers and compares them to a player's input of four numbers. 250 points are awarded for each number matched. The code be... show full transcript

Worked Solution & Example Answer:A number matching game stores four winning numbers and compares them to a player's input of four numbers - Scottish Highers Computing Science - Question 8 - 2023

Step 1

Complete the trace table on the first iteration

96%

114 rated

Answer

BreakpointVariableValue
1st iterationindex0
winningNos[index]10
numMatches1

Step 2

Complete the trace table on the second iteration

99%

104 rated

Answer

BreakpointVariableValue
2nd iterationindex1
winningNos[index]14
numMatches2

Step 3

Explain, with reference to the code, why the number of matches always results in 4.

96%

101 rated

Answer

In the code provided, for each input number, there are multiple conditions that check if the input number matches with any of the winning numbers. Since there is a default 'ELSE' that increments the match count, even if none of the numbers match, this will always result in the count being increased. Thus, after all iterations, there will always be four matches counted regardless of the actual inputs.

Join the Scottish Highers students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;