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

Why does this while loop keep looping even when its false? In C++

This is the code in question:

int integer;
while (integer != 0 || integer != 1) {
            cout << "Choose an integer: \n0\n1\n";
            cin >> integer;
            }

When I type 1 it continues looping even though the statement is false.
I have had this problem before or similar but it got fixed in a weird way that seems to not be working right now.
The other code that was having problems was this one:

while(chosen != 1 || chosen != 2 || chosen != 3)
    {
      cin >> chosen;
    }

I got it fixed by doing this:

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

while(chosen < 1 || chosen > 3)

Does annyone know whats happening here? Ty in advance!

>Solution :

let me put you out of your misery

while(chosen != 1 && chosen != 2 && chosen != 3)
    {
      cin >> chosen;
    }
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