nested for loop problem

Reply

Join Date: Sep 2004
Posts: 42
Reputation: the b is an unknown quantity at this point 
Solved Threads: 0
the b the b is offline Offline
Light Poster

nested for loop problem

 
0
  #1
Jul 25th, 2005
I'm making a rock paper scissors game, and in this game there is a nested for loop so that the players challenge each other, the outer loop is supposed to loop through all the players starting with player 1, while the inner loop starts at the last player and moves to the outer loop player, this sounds simple enough but for some reason the loop I am trying to use doesn't work. Here is what the loop looks like:

  1. for (j = 0; j < playerNum; j++)
  2. {
  3. for (k = (playerNum - 1); k > j; k--)
  4. {
  5. if(j == k)
  6. {
  7. continue;
  8. }
  9. players[j].challenge(players[k]); // challenge player[j] with player[k]
  10. /* Save current player's results to gameResults total.
  11.   * Put each player result on a new line.
  12.   */
  13. gameResults += players[j].getWins() + "\n";
  14. }
  15. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1
Reputation: ssniper101 is an unknown quantity at this point 
Solved Threads: 0
ssniper101 ssniper101 is offline Offline
Newbie Poster

Re: nested for loop problem

 
-1
  #2
Feb 10th, 2008
wow
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 12
Reputation: dandan is an unknown quantity at this point 
Solved Threads: 1
dandan dandan is offline Offline
Newbie Poster

Re: nested for loop problem

 
0
  #3
Feb 10th, 2008
  1. for (j = 0; j < playerNum; j++)
  2. {
  3. for (k = (playerNum - 1); k > j; k--)
  4. {
  5. // j==k test not needed, k>j
  6. players[j].challenge(players[k]); // challenge player[j] with player[k]
  7. }
  8. /* Save current player's results to gameResults total.
  9.   * Put each player result on a new line.
  10.   */
  11. gameResults += players[j].getWins() + "\n";
  12. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 15
Reputation: striker3344 is an unknown quantity at this point 
Solved Threads: 2
striker3344 striker3344 is offline Offline
Newbie Poster

Re: nested for loop problem

 
0
  #4
Feb 11th, 2008
i find it hard to get your point!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC