The while loop I have does what it is supposed to do but in a very round about way. I have a while loop(inside a function) that is supposed to call another function for two random numbers(1 - 6). It then checks to see if the sum of those numbers is equal to 7 or the point number which is determined earlier in the program. So basically it loops until it hits a 7 or point. When the loop runs if it is not a 7 or point right away it seems to display the same values for example:
Die 1 = 1
Die 2 = 2
You rolled a 3!
Die 1 = 1
Die 2 = 2
You rolled a 3!
.
.
.
This happens many times and then it gets new values for the dice. If they do not add up to 7 or the point value it will repeat the same message over and over. It keeps doing this until it eventually hits the 7 or point value and exits the loop. Do I need to call the rolling function differently or reset its values somehow? I am not quite sure what I am missing.
Code:
while (still_in != 0){
roll = rolling();
printf("Die 1 = %d\n", roll[0]);
printf("Die 2 = %d\n", roll[1]);
sum = roll[0] + roll[1];
printf("You rolled a %d!\n", sum);
if (sum == 7){
start = start - bet;
printf("You lose. You now have $%d.\n",start);
goto LOOP;}
else if (sum == point){
start = start + bet;
printf("You win! You now have $%d.\n",start);
goto LOOP;}
}
Code:
int *rolling()
{
static int r[1];
int i;
srand( (unsigned)time( NULL ) );
for ( i = 0; i <= 1; ++i)
{
r[i] = rand()%6+1;
}
return r;
}