Smart Students

DSCF3619

We have some very smart students. In C# we are considering problems you can have with conditions if you are checking for valid entries, for example:

if ( flimNo < 1 && filmNo > 5 )
{
// unlikely we will get here
}
else
{

// funny how this part always gets obeyed...

}

I made the point that a number which is less than one and greater than five is pretty much impossible. Quick as a flash, one of our First Years said “Root 36”. Which can be -6 or 6.

FYI, what you really want if you want to reject invalid entries is to change that && (and) to || (or).

if ( flimNo < 1 || filmNo > 5 )
{
// film number is invalid
}
else
{
// film number is valid
}