A spelling game stores 20 words. Each word has an accompanying sound file where an actor’s voice speaks the word.
When the game is running the program repeats the following 20 times:
selects one of the 20 words
loads a sound file matching the selected word
plays the sound file through a speaker
asks the user to type in the word
compares the user’s entry to the stored word
informs the user if they have spelled the word correctly
When the game is over the program displays the total number of words that have been spelled correctly by the user.
Part of the program code is shown below
…
Line 27 REPEAT 20 TIMES
Line 28 SET choice TO <a number between 0 to 19>
Line 29 <load selected sound file>
Line 30 SEND <sound file> TO <speaker>
Line 31 RECEIVE usersWord FROM KEYBOARD
Line 32 IF usersWord = NOT(storedWords[choice]) THEN
Line 33 SEND "Sorry, the correct spelling is " &
storedWords[choice] TO DISPLAY
Line 34 ELSE
Line 35 SEND "Well Done" TO DISPLAY
Line 36 SET correctGuesses TO correctGuesses + 1
Line 37 END IF
Line 38 END REPEAT
Line 39 SEND "You guessed " & correctGuesses & " words
correctly" TO DISPLAY
(i) Identify the logical operator used in the above code.
[1]
(ii) Using a programming language of your choice, re-write Line 28 to show how the value stored in the variable choice would be generated. Your answer should use a function.
[2]
(iii) When the above code was tested several times, it was found that the user was not asked to spell all 20 of the stored words.
Explain why the program did not ask the user to spell every stored word.
[1]