title: Identify how many words are formatted as dates of the form MMDDYY in a string and count them. (C++)
body: <p>The objective of this program is to read a line of characters to count and identify the number of words in the line. It must identify how many of those words are of the format as dates of the form MMDDYY.</p>
  
  <p>For example, if the user enters: "Four score and die captain ago"</p>
  
  <p>The output should be the following.</p>
  
  <p><em>Total number of words: 6</em></p>
  
  <p><em>Number of valid dates: 0</em></p>
  
  <p>If the user enters
  "Four 032356 team ironman seven 231290 ago"</p>
  
  <p>The output should be</p>
  
  <p><em>Total number of words: 7</em></p>
  
  <p><em>Number of valid dates: 1</em></p>
  
  <p>I'm having a problem implementing the function validateDate. Also I don't know whether or not my approach of the date validiation is correct. My sincerest apology if the code is a mess, I'm kinda learning the basics. Thanks in advance.
  Here's the code:</p>
  
  <pre><code>// #include "stdafx.h"
  
  // This program demonstrates the use of dynamic variables
  
  // Dean DeFino
  
  #include &lt;iostream&gt;
  #include &lt;cctype&gt;
  #include &lt;cstring&gt;
  
  using namespace std;
  
  const int MAXNAME = 10;
  
  //Function prototype
  void processCstring(char *);
  bool validateDate(char[], int);
  
  int main()
  {
      int pos;
      char *name = nullptr;
  
      int result;
  
      const int SIZE = 81;    // The maximum size of the C-string.
      char *cstring;          // To hold a C-string
      char goAgain;           // To hold Y or N
  
      cstring = new char[SIZE]; // Fill in code to allocate the character array pointed to by cstring
  
      name = new char[SIZE];    // Fill in code to allocate the character array pointed to by name
  
      cout &lt;&lt; "Enter your last name with exactly 10 characters." &lt;&lt; endl;
      cout &lt;&lt; "If your name has &lt; 10 characters, repeat last letter. " &lt;&lt; endl;
      cout &lt;&lt; "Blanks at the end do not count." &lt;&lt; endl;
  
      for (pos = 0; pos &lt; MAXNAME; pos++)
          cin &gt;&gt; *(name + pos);   // Fill in code to read a character into the name array
                                  // WITHOUT USING a bracketed subscript
      cout &lt;&lt; "Hi ";
  
      for (pos = 0; pos &lt; MAXNAME; pos++)
          cout &lt;&lt; *(name + pos);
  
      do
      {
          cin.ignore();
          // Get a C-string.
          cout &lt;&lt; "\nEnter a C-string containing 80 or fewer characters:\n";
          cin.getline(cstring, SIZE);
  
          // Display the number of words in the C-string.
          cout &lt;&lt; "\nThe number of words in the C-string:  ";
          processCstring(cstring);
  
  
          // Does the user want to do this again?
          cout &lt;&lt; "Process another string? (Y or N) ";
          cin.get(goAgain);
  
          // Validate the input. If the user enter something diferent of y,Y or n,N
          //then ask again for an answer.
          while ((toupper(goAgain) != 'Y') &amp;&amp; (toupper(goAgain) != 'N'))
          {
              cout &lt;&lt; "Please enter Y or N: ";
              cin.get(goAgain);
          }
  
      } while (toupper(goAgain) == 'Y');
  
  
      // Fill in code to deallocate cstring and name (two steps each pointer)
      delete cstring;
      cstring = nullptr;
      delete name;
      name = nullptr;
  
      return 0;
  }
  
  //***************************************************
  // Function processString                               *
  // This function counts the number of words and the  *
  // number of valid datres in a string passed into an str.   *
  //***************************************************
  
  void processCstring(char *cStrPtr)
  {
      char *str = cStrPtr;
      int numWords = 0;
      int numDates = 0;
      int count = 0; // Variable para que el loop no sea infinito.
  
      //****WARNING
      //Do NOT RUN this while loop until you fixed.
      //This is  infinite loop
      while (*(str + count) != '\0')
      {
          if (isspace(*(str + count)))    //Complete the code to count the number of words.
              count++;                    //Skip any leading spaces
          else if (isalnum(*(str + count)) &amp;&amp; isspace(*(str + count + 1)))
              numWords++;
          count++;
  
          (validateDate(str, strlen(str));
              cout &lt;&lt; "h";
  
          //Now count the number of valid dates in the form MMDDAA
          //for example 040390 is a valid date, 230490 is not valid
          // 23jun90 is not valid.
          //Use the function validateDate (pass the word you found as
          //parameter) to validate if the word is a valid date
  
      }
  
      cout &lt;&lt; "\nTotal number of words: " &lt;&lt; numWords + 1 &lt;&lt; endl;
      cout &lt;&lt; "Number of valid dates: " &lt;&lt; numDates &lt;&lt; endl;
  }
  
  
  //***************************************************
  // Function validateDate                               *
  // This function validate if a word received as a parameter  *
  // is a valid date.                                     *
  //***************************************************bool 
  
  validateDate(char myPass[], int size)
  {
      bool answer = false;
      int i = 0; // Arreglar
  ​
      while (i &lt; size &amp;&amp; !answer)
      {
          /*Validar que sea un string de 6 chars
              Que el primer char1 &lt; 2
              char1 + char2 &lt;= 9
              char3 &lt; 4
              char3 + char4 &lt;= 11*/
  ​
          if (static_cast&lt;int&gt;(myPass[0]) &lt; 2)
          {
              if (static_cast&lt;int&gt;(myPass[0]) + static_cast&lt;int&gt;(myPass[1]) &lt;= 9)
              {
                  if (static_cast&lt;int&gt;(myPass[2]) &lt; 4)
                  {
                      if (static_cast&lt;int&gt;(myPass[2]) + static_cast&lt;int&gt;(myPass[3]) &lt;= 11)
                      {
                          answer = true;
                          i++;
                      }
                  }
  
              }
          }
      }
      return answer;
  }
  </code></pre>