C++ 4 players in a array after element 3 reset to 0 with modulus [closed]
4 players in a array after element 3 reset to 0 with modulus. So if its players 3 turn it will reset to player 1 witch is element 0.
Use something like this:
player = (player + 1) % 4;
You're somehow missing your actual question? If you'd like to "loop" some index over 0 to 3 (for 4 players) just do something like this:
int currentPlayer = 0;
int numPlayers = 4;
// ...
currentPlayer = (currentPlayer + 1) % numPlayers;
精彩评论