mercredi 25 octobre 2017

do-while loop does not end

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 if statement (you have give 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? Thanks in advance.

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;

}

Aucun commentaire:

Enregistrer un commentaire