while(decision1 != 1 || decision1 != 2) why does this keep repeating even though decision is already 1 or 2

This is the code. Why does it keep repeating even though decision is already 1 or 2?

    std::cout << "How many toppings do you want? (1/2): ";
    std::cin >> decision1;
        
    while(decision1 != 1 || decision1 != 2)
    {
        std::cout << "Please enter either 1 or 2\n";
        std::cout << "How many toppings do you want? (1/2): ";
        std::cin >> decision1;
    }

>Solution :

When decision1 == 1, the condition decision1 != 2 is true, and vice-versa.

Since decision1 cannot be both 1 and 2, decision1 != 1 || decision1 != 2 is always true.

Leave a Reply