Logic error with array and for loop
<p>If I enter an amount of <code>5</code> players (<code>5</code> elements in the <code>score[]</code> array) in the <code>scanf("%d", &amp;numPlayers)</code> the for loop cycles the players all the way up to player 5 (element 4 of <code>score[]</code>), and then jumps to the winMsg function. The score of that element is a large value, even though I set all the <code>score[]</code> element's to <code>0</code> in the first for loop. If I enter <code>6</code> or more elements, the second for loop never executes. Program runs no problem with <code>4</code> or less elements in <code>score[]</code>. I am using gedit and terminal in Ubuntu. Any ideas? Fairly new to programming. I appreciate any help.</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;time.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

int rollDie(){
 return (rand()%6 + 1);
}

void winMsg(int winRoll, int player, int winScore){
printf("Congratulations Player %d! Your winning roll was a %d, putting your score at %d!\n\nGame Over\n\n", player + 1, winRoll, winScore);
return;
}


int main(){

srand(time(NULL));
int numPlayers = 0;
int roll = 0;
int i = 0;
int score[numPlayers];
char choice[2];

printf("Welcome to the \"Roll to Win\" game. Each roll adds to the current player's score, according to the die's number. A roll of 1 will cause the player to recieve no points that round, and then be skipped to the next player. First player to reach 100 or over wins! Please enter number of players: \n\n");
scanf("%d", &amp;numPlayers);
printf("\n");

while (numPlayers &gt;= 100 || numPlayers &lt;= 0){
    printf("Please enter a number of players less than 100, greater than 0.\n\n");
    scanf("%d", &amp;numPlayers);
    printf("\n");
}

for (i = 0; i &lt; numPlayers; ++i){
    score[i] = 0;
    printf("Set Player %d score to %d.\n", i + 1, score[i]);
}   

printf("Starting with Player 1.\n\n");

for (i = 0; i &lt; numPlayers; ++i){

    roll = rollDie();

    if (roll == 1){
        printf("Player %d rolled a 1. Skipping turn. Current score: %d.\n\n", i + 1, score[i]);
    }
    else{
        do{
            score[i] += roll;
            if (score[i] &gt;= 100){
            winMsg(roll, i, score[i]);
            exit(0);
            }
            printf("Player %d rolled a %d, continue rolling (enter r to roll, or sr to stop rolling)? Current score: %d.\n\n", i + 1, roll, score[i]);
            scanf("%s", choice);
            printf("\n");

            while ((strcmp ("r",choice) != 0) &amp; (strcmp ("sr",choice) != 0)){
                printf("Please enter a correct selection (enter r to roll, or sr to stop rolling).\n\n");
                scanf("%s", choice);
                printf("\n");
            }

            if (strcmp ("sr",choice) == 0){
                printf("Player %d decided to stop rolling. Continuing to next player.\n\n", i + 1);
                break;
            }

            roll = rollDie();
            if (roll == 1){
                printf("Player %d rolled a 1. Skipping turn. Current score: %d.\n\n", i + 1, score[i]);
                break;
            }

        } while (strcmp (choice,"r") == 0);
    }

    if (i == numPlayers - 1){
        i = -1;
    }
}



}
</code></pre>