I need help with a program I am making. The user inputs the values to 3 variables. I need the loop to stop when the variables are equal.
I tried putting:
1 2 3 4 5 6
int main()
{
while (variable1 != variable2)&(variable2 != variable3){
//code
}
}
but it didn't work, because the loop ended when 1 and 2 were equal. Can you help?
I have a limited c++ knowledge but I am quick to learn. Thanks.
As long as both operands are bool - yes, that's correct.
However, very often logical tests are carried out on other types, which is why it's good practise to keep the appropriate operators for the appropriate purpose.
1 2 3 4 5 6 7 8 9 10 11 12
int A = 1;
int B = 2;
if (A && B)
cout << "&& ok" << endl;
else
cout << "&& fail" << endl;
if (A & B)
cout << "& ok" << endl;
else
cout << "& fail" << endl;