Question 13
AQA Computer Science June 2023 Paper 1A (8525/1A)GCSE6 marks
On the specification
- 3.2 Programming
Question text
13 A programmer is writing a game. The game uses a 3 x 3 grid containing nine box squares. Figure 14 A B C 1 2 3 X In the game, a square on the grid is referred to by a letter and a number. For example, square C3 in Figure 14 contains an X. Figure 15 shows part of a C# program that checks the grid reference entered by a player. The grid reference is valid if: • there are exactly two characters • the first character entered is A, B or C • the second character entered is 1, 2 or 3. Figure 15 bool check = false; while (check == false) { string square = ""; while (square.Length != 2) { Console.Write("Enter grid reference (eg C2): "); square = Console.ReadLine(); square = square.ToUpper(); } The C# function ToUpper()converts letters into uppercase, eg b1 would be converted to B1 Extend the program from Figure 15 so it completes the other checks needed to make sure a valid grid reference is entered. Your extended program must: • use the variable check • repeat the following steps until a valid grid reference is entered: o get the user to enter a grid reference o output an appropriate message if the grid reference entered is not valid. You should use meaningful variable name(s) and C# syntax in your answer. The answer grid contains vertical lines to help you indent your code. [6 marks] bool check = false; while (check == false) { string square = ""; while (square.Length != 2) { Console.Write("Enter grid reference (eg C2): "); square = Console.ReadLine(); square = square.ToUpper(); } }