This section of code is supposed to display a menu with two options, read the input and go to the corresponding function. If the user enters something other than 1 and 2 the program should warn the user and show the menu to ask user to enter the input again. This process will keep repeating until the user puts the right input.
I'm trying to find a way to repeat the loop only when the user inputs something other than 1 and 2 (so that the user can enter the appropriate response this time).
However, when I use a while loop like this, it loops no matter what the input is.
Any help is much appreciated.
char input;
displayWellDoneMenu();
scanf("%c", &input);
while (input != '1' || input != '2')
{
    printf("You must select 1 or 2!\n");
    displayWellDoneMenu();
    scanf("%c", &input);
    rewind(stdin);
    system("cls");
}
switch (input)
{
    case'1':
        additionIntermediate();
        break;
    case '2':
        main();
        break;
}
    
input != '1' || input != '2'is always true no matter whatinputis. You wantinput != '1' && input != '2'inputisn't initialized the first time you test it. So I'd recommend setting it to some initial value not 1 or 2, or better, use one of the answers given by others which work around that issue."You must select 1 or 2!\n"? BTW:rewind(stdin);is not well defined.rewind(stdin)is problematic. It may not do anything if the input is a terminal or pipe; it does nothing good and much harm if the input is coming from a file. An alternative that people often think of is usingfflush(stdin), but that is also problematic. You should probablyuse" %c"(with a leading blank) for the format string, and think about gobbling input to end of line (or EOF if no EOL occurs before EOF) —int c; while ((c = getchar()) != EOF && c != '\n') ;.