I am working on a Turing application that displays a random number, and then displays how many times that number is rolled, but then finds the mode, the highest value of the amount of times the random is rolled, and displays which number (1-6) is rolled the most. Thanks for the help.
var numberDice : int
var freq : array 1 .. 6 of int
var highestNum : int
highestNum := 0
for j : 1 .. 6
freq (j) := 0
end for
for i : 1 .. 25
randint (numberDice, 1, 6)
freq (numberDice) := freq (numberDice) + 1
end for
for counter : 1 .. 6
if freq (counter) > highestNum then
highestNum := freq (counter)
end if
end for
put "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
put "Number Frequency"
put "1 ", freq (1)
put "2 ", freq (2)
put "3 ", freq (3)
put "4 ", freq (4)
put "5 ", freq (5)
put "6 ", freq (6)
put " "
put "Mode: ", highestNum
put "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
You need an additional variable to hold the die you found to be highest:
var highestNum : int
var highestIndex : int
highestNum := 0
highestIndex := 0
. . .
highestNum := freq (counter)
highestIndex := counter