How to make a loop that keeps track of whose turn it is and there score?

http://pastebin.com/yw2TZZKw

This is my code, but how can I implement this?
Use the modulo operator:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool endConditionMet = false;
int playerScore[4];
int numPlayers = 4;

for( int i = 0; i< numPlayers; i = (i+1)%numPlayers){
	int diceRoll = // call the function that you are interested in
	// Get user input here

	if( endConditionMet == true ){
		break; //This is the only way to stop the loop
		// maybe your end condition can be if a score limit is met.
	}
	playerScore[i] += diceRoll;

}


Note: The line: i < numPlayers doesn't really do anything because it is always true. Therefore, you can replace this with true.

This iterates from 0 to numPlayers and wraps back around to 0 infinitely. Here is info:
http://stackoverflow.com/questions/3589976/what-are-the-practical-uses-of-modulus-in-programming
Last edited on
Topic archived. No new replies allowed.