Question 3

AQA Computer Science June 2024 Paper 1A (8525/1A)GCSE6 marks

On the specification

3.1
3.2 Programming
3.2
3.2 Programming
3.3
3.2 Programming
Question text

3 Figure 3 shows an incomplete C# program for a number guessing game. box • Line numbers are included but are not part of the program. Figure 3 1 Random rGen = new Random(); 2 int randomNumber; 3 4 Console.WriteLine("Enter a number"); 5 int userNumber = Convert.ToInt32(Console.ReadLine()); 6 while (userNumber < 1 || userNumber > 100) 7 { 8 Console.WriteLine("Invalid number"); 9 userNumber = Convert.ToInt32(Console.ReadLine()); 10 } 11 Console.WriteLine("Valid number entered"); 12 if (randomNumber == userNumber) 13 { 14 Console.WriteLine("Number guessed correctly"); 15 } 3.1 The program should generate a random number between 1 and 100 (including 1 and 100). This will be the number the user has to guess. Write the C# code that should be used on line 3 in Figure 3 to: • generate a random number between 1 and 100 inclusive • assign this number to the appropriate variable from the program. You must use rGen.Next(a, b) in your C# code. rGen.Next(a, b) generates a random integer in the range a to b starting at a but finishing one before b [2 marks] 3.2 Complete the test plan in Table 1 to test the validation of userNumber in the box program in Figure 3. [2 marks] Table 1 Test number Test type Test data Expected result 1 Erroneous 150 2 Boundary 3 Normal Valid number entered 3.3 In an earlier version of the program in Figure 3, line 6 contained one syntax error and one logic error: whil (userNumber < 1 || userNumber >= 100) Complete the table to describe the errors in the program on line 6. [2 marks] Error type Description Syntax error Logic error