MATLAB: 5 person die roller

berakwhile loop

I am trying to build a die roller, for a groupe of people, that says which of 5 people has gotten the 6. Right now the die roller tells how many rolls where made. I want it to tell which of the five persons (who roll out of turn) made the roll. So if the roll number (called i) is greater then 5 (number of players) we need to subtract 5 until it is. And then display which person made the roll and how many total rolls were made.
Code die roller:
i=0; % number of throws
while 1
i = i + 1;
dieRoll = randi(6); % gives a random number 1-6
if dieRoll < 6;
continue % continue if it's not a 6
else
break % break if it is
end
end
disp(i) %display number of throws
I have then tried to implicate an other if else statement, but out of luck:
if i > 5
while i > 5
i=i-5;
end
else
i=i
end

Best Answer

Mads - I think that your logic could be simplified to
i = i + 1;
if i > 5
i = 1;
end
So if the roll is six, then we reset to one to indicate that player one is rolling.
You may also want to consider renaming this variable to indicate what it actually represents (i.e the playerId) and to avoid confusion with the imaginary number (which MATLAB represents using i and j).