title: C++ validating driving licence program
body: <p>I have been banging my head against this for about 2 hours so have decided to get a second or more set of eyes on it. if you can help would be greatly appreciated not to bothered if the answer is in c++ or logic just cant see why its not working.
  ( The issue I am getting is "string subscript out of range" which is occurring during run time ) The program should take in 9 char into a string the first 5 should be numbers and last 4 should be letters.</p>
  
  <pre><code>cout&lt;&lt;"please enter in licence number :";
  cin&gt;&gt;licence;
  while(licence.length()!=9)
  {
    cout&lt;&lt;"Sorry please re-enter licence should be 9 characters"&lt;&lt;endl&lt;&lt;"first 5 are numbers last 4 are Letters :";
    cout&lt;&lt;"please enter in licence number :";
    cin&gt;&gt;licence;
    system("CLS");
  }
  for(int i=0;i&lt;=4;i++)
  {
    for(int j=4;j&lt;=9;j++)
    {
      while(!isdigit(licence[i])&amp;&amp;!isalpha(licence[j]))
      {
        cout&lt;&lt;"Sorry please re-enter licence should be 9 characters"&lt;&lt;endl&lt;&lt;"first 5 are numbers last 4 are Letters :";
        cout&lt;&lt;"please enter in licence number :";
        cin&gt;&gt;licence;
        system("CLS");
      }
    }
  }
  </code></pre>
  
  <p>Ok so this is my updated function but still not working correctly</p>
  
  <pre><code>bool islicensevalid(string license)
  {
     if (license.length() != 9) 
     {
       cout&lt;&lt;"Not nine characters long "&lt;&lt;endl;
       return false;
     }
  
     for (unsigned short index = 0; index &lt; 5; ++index)
     { 
        if(!isdigit(license[index]))
        {
          cout&lt;&lt;"first 5 characters aren't numbers"&lt;&lt;endl;
          return false;
        }
     }
  
     for (unsigned short index = 5; index &lt; 9; ++index)
     {    
         if(!isalpha(license[index]))
         {
            cout&lt;&lt;"final 4 characters aren't letters"&lt;&lt;endl;
            return false;
         }
     }
     return true;
  }
  </code></pre>
  
  <p>Again I have changed the numbers but it either has the same error as before or it says the last 4 digits are letters</p>