title: Testing a string or char for upper, lower case and numbers C++
body: <p>I'm trying out an exercise where I have the user write a pass and I have to check the pass for length (must be at least 6 characters), upper case, lower case, and at least 1 number. for some reason, when I try to make it work, it wont detect both upper case and lowercase. even when "lower" or "upper" are == true, it still goes to the nested if (!lower) or if (!upper) conditional and runs that code block when the other is false.</p>
  
  <p>can anyone show me where the logic is wrong? I'm not understanding why its even accessing an if with it false if the bool variable is set to true.</p>
  
  <pre><code> bool verified(const char *pass)
   {
       int length = strlen(pass);
       bool lower, upper, number;
       lower = hasLower(pass);
       upper = hasUpper(pass);
       number = hasNumber(pass);
       if (length &lt; 6)
       {
           cout &lt;&lt; "INVALID: Your pass does not contain enough characters";
           return false;
       }
       else
       {
           if (lower &amp;&amp; upper &amp;&amp; number)
           {
               cout &lt;&lt; "Your pass is valid and verified. Congrats!";
               return true;
           }
           if (!lower)
           {
               if (!number)
               {
                   cout &lt;&lt; "INVALID: Your pass does not contain lower case letters or at least 1 number";
                   return false;
               }
               if (!upper);
               {
                   cout &lt;&lt; "INVALID: Your pass does not contain lower case or upper case letters";
                   return false;
               }
               cout &lt;&lt; "INVALID: Your pass does not contain lower case letters";
               return false;
           }
           if (!upper);
           {
               if (!number)
               {
                   cout &lt;&lt; "INVALID: Your pass does not contain upper case letters or at least 1 number";
                   return false;
               }
               if (!lower);
               {
                  cout &lt;&lt; "INVALID: Your pass does not contain upper case or lower case letters"1;
                  return false;
               }
               cout &lt;&lt; "INVALID: Your pass does not contain upper case letters";
               return false;
           }
           if (!number)
           {
               cout &lt;&lt; "INVALID: Your pass does not contain at least 1 number";
               return false;
           }
       }
   }
  </code></pre>
  
  <p>method for checking upper case</p>
  
  <pre><code> bool hasUpper(const char *pass)
   {
       bool upper;
       for (int i = 0; i &lt; strlen(pass); i++)
       {
           upper = isupper(pass[i]);
           if (upper == true)
           {
               return true;
               break;
           }
       }
       return false;
   }
  </code></pre>
  
  <p>method for checking lower case</p>
  
  <pre><code> bool hasLower(const char *pass)
   {
       bool lower;
       for (int i = 0; i &lt; strlen(pass); i++)
       {
           lower = islower(pass[i]);
           if (lower == true)
           {
               return true;
               break;
           }
       }
       return false;
   }
  </code></pre>
  
  <p>method for checking for number</p>
  
  <pre><code> bool hasNumber(string pass)
   {
       if (pass.find('0') != string::npos ||
           pass.find('1') != string::npos ||
           pass.find('2') != string::npos || 
           pass.find('3') != string::npos || 
           pass.find('4') != string::npos || 
           pass.find('5') != string::npos || 
           pass.find('6') != string::npos ||
           pass.find('7') != string::npos || 
           pass.find('8') != string::npos ||
           pass.find('9') != string::npos)
           return true;
       else
           return false;
   }
  </code></pre>