为什么程序最多执行两次
#include<stdio.h>
#include<time.h>
#include<stdbool.h>
#include<stdlib.h>
bool play_game(void);
int roll_dice(void);
int main() {
int n = 0,b=0;
char a;
while(true) {
srand((unsigned)time(NULL));
if (play_game()) {
printf("You win\n");
n++;
}
else {
printf("You lose\n");
b++;
}
printf("Play again?");
if ((a=getchar())!= 'y')
break;
}
printf("Wins:%d Losses:%d\n", n, b);
return 0;
}
int roll_dice(void) {
int c, B;
c = rand() % 6+1;
B = rand() % 6+1;
return c + B;
}
bool play_game(void) {
int d;
d = roll_dice();
printf("You rolled:%d\n", d);
if (d == 7 || d == 11)
return true;
if (d == 2 ||d == 3 || d == 12)
return false;
printf("Your point is %d\n",d);
for (;;) {
int e = roll_dice();
if (e == d) {
printf("You rolled: %d\n",d);
return true;
}
if (e == 7) {
printf("You rolled:%d\n",e);
return false;
}
printf("You rolled:%d\n",e);
}
}
