Hi, i am having a bit of trouble looping a program. The program keeps looping even if i entered 1 or 0 for the variable repeat.Hope you guys are able to help me out.Thanks
# include <iostream>
usingnamespace std;
int main()
{
int a, b, c, repeat;
do
{
.... //some if and else statement
cout<< "Do you want to compare another? (yes=1,no=0) "; cin>> repeat;
if(repeat!=1 || repeat!=0)
{
cout<< "Bad input. Do you want to compare another? (yes=1,no=0) "; cin>> repeat;
while(repeat!=1 || repeat!=0)
{
cout<< "Bad input. Do you want to compare another? (yes=1,no=0) "; cin>> repeat;
cin.get();
}
}
else{}
}
while (repeat==1);
cin.get();
cin.get();
return 0;
}
|| returns true if at least one of the sides are true. This means that the only way to get false is if both sides are false.
If repeat!=1 is false then repeat!=0 must be true and vice versa so there is no way the loop condition can be false.