这是有问题的 while 循环和开关(track1 定义了一个更大的循环,此处未显示):
while (track6 ==1)
{
printf ("would you like to play again? Y or N?\n");
scanf ("%c", &response);
switch (response)
{
case 'Y' : track6 = 2;
break;
case 'N' : printf ("thanks for playing!\n");
track6 = 2, track1 = 2;
break;
default : printf ("response is case-sensitive and must be either Y or N. your response is invalid. please reenter.\n");
}
}
我收到的输出是:
would you like to play again? Y or N?
response is case-sensitive and must be either Y or N. your response is invalid. please reenter.
would you like to play again? Y or N?
(提示输入,然后正确执行)
似乎它正在执行第一个 printf,跳过 scanf,执行默认值,回到循环顶部并从那里正常运行。知道为什么吗?这只是我的第三周编程,因此外行的术语受到赞赏。