Question 16
AQA Computer Science June 2023 Paper 1C (8525/1C)GCSE11 marks
On the specification
- 3.2 Programming
Question text
16 Question 16 is about a dice game played against a computer. box The aim of the game is to get as close to a score of 21 as you can, without going over 21. If your score goes over 21 then you lose. The player’s score starts at 0. For each turn: • two dice (each numbered from 1 to 6) are rolled • the total of the two dice rolls is added to the player’s score • the value of each dice and the player’s new total score is output • if the current score is less than 21, the player is asked if they would like to roll the dice again: if the player says yes, they get another turn; otherwise, the game ends. At the end of the game, the program should work as follows: • if the final score is 21, output a message to say the player has won • if the final score is greater than 21, output a message to say the player has lost • if the final score is less than 21, the program generates a random number between 15 and 21 inclusive: o if this random number is greater than the player’s final score, output a message to say the player has lost o otherwise, output a message to say the player has won. Figure 17 shows the output of a program that plays this dice game. Figure 17 Roll 1: 1 Roll 2: 4 Current score: 5 Would you like to roll again? yes Roll 1: 1 Roll 2: 6 Current score: 12 Would you like to roll again? yes Roll 1: 1 Roll 2: 2 Current score: 15 Would you like to roll again? yes Roll 1: 6 Roll 2: 1 Current score: 22 You lost! Write a VB.NET program to simulate this game. The first line has been written for you in the answer grid. The dice rolls are carried out by the program generating random numbers between 1 box and 6. You will need to use the VB.NET function r.Next(a, b) which generates a random integer in the range a to b starting at a but finishing one before b. You should use meaningful variable name(s) and VB.NET syntax in your answer. The answer grid below contains vertical lines to help you indent your code. [11 marks] Dim r As Random = New Random()