循环程序运行一次后不能执行了,而且题目还有要求
附件是题目,求解答,为什么程序只能运行两次#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<stdbool.h>
int roll_dice(void);
bool play_game(void);
char s=0;
int m, n;
int main()
{
srand((unsigned)time(NULL));
play_game();
printf("Play again?");
while (1) {
scanf_s("%c", &s,1);
if (s == 'y' || s == 'Y')
{
play_game();
}
else
{
break;
}
printf("Play again?");
}
printf("Wins:%d Losses:%d", m, n);
return 0;
}
int roll_dice(void)
{
int a, b;
a = rand() % 6 + 1;
b = rand() % 6 + 1;
printf("You rolled:%d\n", a + b);
return a+b;
}
bool play_game()
{
int i, j = 0;
i = roll_dice();
if (i == 7 || i == 11)
{
printf("You win!\n");
m++;
return true;
}
else if (i == 2 || i == 3 || i==12)
{
printf("You lose!\n");
n++;
return false;
}
else
{
j = i;
printf("You point is %d\n", j);
i = roll_dice();
}
while (1)
{
if (i == j)
{
printf("You win!\n");
m++;
return true;
}
else if (i == 7)
{
printf("You lose!\n");
n++;
return false;
}
else
{
i = roll_dice();
}
}
}