<分区>
我正在尝试做一个 do-while 循环,用户输入一个值,1 或 0,如果它不是 1 或 0,那么循环将要求他们再次执行,直到他们输入 1 或 0 . 但是,在运行时,当我输入 1 或 0 时,它会继续打印 if 语句中的内容
you have given an incorrect response, it must either be 1 or 0
即使我进入了 1/0,也永远停留在这个循环中。它是否存储 enter 键?我缺少什么以及如何解决这个问题?
int validateresultmanual(char* word, char* suggestion)
{
int choice;
int result;
if(suggestion == NULL)
{
result = FALSE;
}
else
{
do
{
printf("Enter 0 for yes or 1 for no: Do you want to change %s to %s?\n", word, suggestion);
scanf("%c", &choice);
if(choice != 0 || choice != 1)
{
printf("You have given an incorrect response, it must either be 1 or 0\n");
}
else if(choice == 0)
{
printf ("\n yaaaaaaaaaaaaa \n");
result = TRUE;
}
else if (choice == 1)
{
result = FALSE;
}
} while (choice != 0 || choice !=1 );
}
return result;