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 8
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Breakpoint
Variable
Value
1st iteration
index
0
winningNos[index]
10
numMatches
1
Step 2
Complete the trace table on the second iteration
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Breakpoint
Variable
Value
2nd iteration
index
1
winningNos[index]
14
numMatches
2
Step 3
Explain, with reference to the code, why the number of matches always results in 4.
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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...