A programmer has been asked to create a module RollDice() to simulate multiple rolls of a dice. This module will be used as part of a program for a game. The module will: step 1 - take a positive integer parameter representing the number of times the dice will be rolled step 2 - simulate one roll of the dice by generating a random integer between 1 and 6 inclusive step 3 - output the integer generated step 4 - repeat, as required from step 2 step 5 - calculate the average value of the random integers generated step 6 - return the average value. Write pseudocode for the module RollDice()
- Write pseudocode for the module RollDice()[7]
Mark scheme
Marking points from the official mark scheme (May/June 2025). The mark or mark type is shown in brackets.
- [7] Example solution: FUNCTION RollDice(NoOfTimes : INTEGER) RETURNS REAL DECLARE RollValue : INTEGER DECLARE Average : REAL DECLARE Count : INTEGER DECLARE Sum : INTEGER Sum <- 0 FOR Count <- 1 TO NoOfTimes RollValue <- INT(RAND(6)) + 1 OUTPUT RollValue Sum <- Sum + RollValue NEXT Count Average <- Sum / NoOfTimes RETURN Average ENDFUNCTION
- MP1 Declare all variables used and initialise Sum to 0
- MP2 Loop for 'number of times' parameter
- MP3 Use RAND() function with Integer parameter in a loop
- MP4 Use INT() function in a loop
- MP5 Generate a random integer between 1 and 6 in a loop
- MP6 Output each value generated in a loop
- MP7 Calculate Sum and if Average used check declared as REAL and return Average and check function header returns REAL
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →