I'm attempting to do a do-while loop where the user inputs a value, either 1 or 0, and if it is not 1 or 0 then the loop will ask them to do it again until they enter 1 or 0. However, in runtime, when i enter 1 or 0, it will keep printing the stuff inside the if statement
you have given an incorrect response, it must either be 1 or 0
even though i have entered 1/0, staying in this loop forever. Does it store the enter key? What am i missing and how do i fix this?
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;
}
choicefor which bothchoice != 0andchoice != 1would evaluate tofalse; that's the number you need to enter in order to end the loop.