AQA · GCSE · Computer Science · Higher
Checking consecutive tile values in C#
| Subroutine | Purpose |
|---|---|
| getTile(row, column) | Returns the number of the tile on the board in position (row, column). |
The blank space on a board is represented by 0. Figure 18 and Figure 19 show example boards.
| row \ column | 0 | 1 | 2 |
|---|---|---|---|
| 0 | 5 | 2 | 0 (blank) |
| 1 | 1 | 3 | 4 |
| 2 | 6 | 7 | 8 |
| row \ column | 0 | 1 | 2 |
|---|---|---|---|
| 0 | 2 | 3 | 4 |
| 1 | 5 | 1 | 0 (blank) |
| 2 | 7 | 8 | 6 |
For the board in Figure 18, the program would display No. For the board in Figure 19, the program would display Yes.
Write a C# program to check that, in the first row, the second tile number is one more than the first and the third tile number is one more than the second. Display Yes when both conditions are met and No otherwise. You must use getTile. Use meaningful variable name(s) and C# syntax.
Write your answer first. You can study the marking guidance whenever you need it.
Study the marking See what earns credit and compare it with a full-mark answer.
Marking points
- 1 Uses suitable selection for the combined requirement.
- 2 Checks three values for consecutive increments of exactly one.
- 3 Uses first-row coordinates (0,0), (0,1) and (0,2).
- 4 Outputs exactly one of Yes or No on every route.
Full-mark answer
if ((getTile(0, 1) - getTile(0, 0) == 1) && (getTile(0, 2) - getTile(0, 1) == 1)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); }
Why this answer loses marks
I checked only that each later tile was larger and used separate unconditional statements for both messages.
The values must increase consecutively, and exactly one outcome should be displayed for each board.