title: C++ Check if String contains atleast 1 digit and 1 letter
body: <p>I am trying to check if a string input contains atleast one numeric digit and one letter before returning true.</p>
  
  <p>My approach was first by looping through the word.
  If the word does not contain either <code>isalpha</code> or <code>isdigit</code> then return false.</p>
  
  <p>After that check, I create two counts (One for digits and one for letters). I check if <code>isalpha</code> then add one to the count. I then check if <code>isdigit</code> and add to that count.</p>
  
  <p>Finally I check if both counts are greater than or equal to 1 (Meaning it contains atleast one digit and one letter) and return true. I know counts are not the best method but I am just trying to test the method but it fails to work and I'm not sure where my logic is wrong.</p>
  
  <pre><code>bool isDigitLetter::filter(string word) {
      int digit = 0;
      int letter = 0;
      if(word.empty()) {
          return false;
      }
      for(int i = 0; i &lt; word.length(); i++) {
          if(!isalpha((unsigned char)word[i]) || !isdigit((unsigned char)word[i])) {
              return false;
          }
      }
      for(int x = 0; x &lt; word.length(); x++) {
          if(isalpha((unsigned char)word[x])) {
                  letter+=1;
          }
          if(isdigit((unsigned char)word[x])) {
              digit+=1;
          }
      }
      if(digit &amp;&amp; letter&gt;= 1) {
          return true;
      }
  }
  </code></pre>
  
  <p>I was thinking maybe using <code>isalnum</code> but that would return true if it contains either but not checking if it contains atleast one of each.</p>