-
infinite stupidity
Code:
using namespace std;
int inputAndValidate(char position,int points)
{
do{
cout<<"Please enter the posistion (F or B)"<<endl;
cin>>position;
cout<<position<<endl;
} while(position!='F' || position!='B');
return 0;
}
why does this loop? no matter what input it just loops, please assist the village idiot...
-
One of those conditions is always going to be true. A character can't equal 'F' and 'B' at the same time...
-
Ok i understand it like this
do the loop while position does not equal f or equal b...
has my logic gone astray?
-
!= does mean "does not equal", doesn't it?
-
The condition that you are looking for:
Code:
while (!(position == 'B' || position == 'F'));
Which is the same as:
Code:
while (position != 'B' && position != 'F');
-
Ok ok i got it, I must use && instead of || because no matter what using the || will always result in the condition being true... thanks anon!
-
Read the logic out loud:
Loop while position is not equal to 'B' OR position is not equal to 'F'.
Or the other one:
Loop while position is not equal to 'B' AND position is not equal to 'F'.
Tell me which one sounds most reasonable?
It's no different than communicating with a friend, for example, on what he or she should do. It's not programming - it's logic!
-
Where's that thread on boolean math being important for programming?
-