Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading