2013 Old Spec

From AQA Computer Science
Jump to: navigation, search

Question 4

The algorithm, represented using pseudo-code in Figure 4, and the variable table, Table 3, describe a simple two player game. Player One chooses a whole number between 1 and 10 (inclusive) and then Player Two tries to guess the number chosen by Player One. Player Two gets up to five attempts to guess the number. Player Two wins the game if they correctly guess the number, otherwise Player One wins the game.


Note that in Figure 4, the symbol <> means "is not equal to".


Figure 4

   OUTPUT "Player One enter your chosen number: "
INPUT NumberToGuess
WHILE NumberToGuess < 1 OR NumberToGuess > 10 DO
OUTPUT "Not a valid choice, please enter another number: "
INPUT NumberToGuess
ENDWHILE
Guess = 0
NumberOfGuesses = 0
WHILE Guess <> NumberToGuess AND NumberOfGuesses < 5 DO
OUTPUT "Player Two have a guess: "
INPUT Guess
NumberOfGuesses = NumberOfGuesses + 1
ENDWHILE
IF Guess = NumberToGuess
THEN OUTPUT "Player Two wins"
ELSE OUTPUT "Player One wins"

Table 3

Identifier Data type Purpose
NumberToGuess Integer Stores the number entered by Player One
NumberOfGuesses Integer Stores the number of guesses that Player Two has made so far
Guess Integer Stores the most recent guess made by Player Two



What you need to do

  1. Write a program for the above algorithm.
  2. Test the program by conducting the tests Test 1 and Test 2.


Test 1

Test that your program works correctly by conducting the following test:

  • Player One enters the number 0
  • Player One enters the number 11
  • Player One enters the number 5
  • Player Two enters a guess of 5


Test 2

Test that your program works correctly by conducting the following test:

  • Player One enters the number 6
  • Player Two enters guesses of 1, 3, 5, 7, 10