Search code examples
asciiboolean-operationstruthtable

Truth tables issue


When I check my input from a text box, I pass it into a loop to check individual characters.

I'm a little uncertain as to why this is happening, but when I input a "/", the function reads it as false?

 // Checks the Password contains the correct input 
 for (i = 0; i < passwordLength; i++)
 {
     v = Convert.ToInt32(passwordArray[i]);
     // (not 0-9 or not A-Z or not a-z) 
     // "/"(converted to 47) reads as (true)+(true)+(false) = false
     if ((v < 48 || v > 57) && (v < 65 || v > 90) && (v < 97 || v > 122))
     {
         e = 2;
     }
 }

Solution

  • try this in your if condition

    if (!(v >= 48 && v <= 57) && !(v >= 65 && v <= 90) && !(v >= 97 && v <= 122))