Write a program, using AQA pseudocode, that simulates rolling two six-sided dice. The program should:
- keep rolling both dice until a double (both dice the same value) is rolled
- then output how many rolls were needed.
You should use the subroutine RANDOM_INT(a, b), which returns a random integer between a and b inclusive. [6]
- Uses RANDOM_INT(1, 6) for a dice roll(1)
- Generates two separate values (one for each dice) on each roll / inside the loop(1)
- Uses a loop (REPEAT…UNTIL or WHILE) that ends when the two dice values are equal(1)
- Initialises a counter (e.g. rolls ← 0) before the loop(1)
- Increments the counter once for each roll, inside the loop(1)
- Outputs the counter after the loop has finished(1)
- Answer: e.g.
rolls ← 0 REPEAT d1 ← RANDOM_INT(1, 6) d2 ← RANDOM_INT(1, 6) rolls ← rolls + 1 UNTIL d1 = d2 OUTPUT rolls - Examiner tip: If the dice are rolled before the loop and not again inside it, the loop never ends. Generate the values inside the loop.