Reminder Challenge

Challenge

Four Player Game

We need to find out which player to go first.

Players = 4 or 0,1,2,3

Using the random number 63 who goes first?

63 % 4 = 15 (15x4=60) r3 = 3+1 = Player 4 (Due to starting at 0)

switch( rand % 4 )
{
default:
case 0:
// Player 1
break;
case 1:
// Player 2
break;
case 2:
// Player 3
break;
case 3:
// Player 4
break;
}

I got: 222
222 % 4 = 55 r 2
2+1 = Player 3

Next Player: 91

I will do this a little differently to show an alternative way to find the remainder. Rather than multiplying the decimal remainder by the divisor as discussed in the video, I floor the result of the division and multiply by the divisor, then subtract that result from the dividend to get the remainder. (Bit easier to think in whole numbers)

91 / 4 = 22.75
floor(22.75) = 22
22 * 4 = 88
91 - 88 = 3
3 + 1 = Player 4

Next player: 33

Privacy & Terms