title: MS studio 17 Stack around the variable was corrupted
body: <p>Hi i keep getting a stack around the variable nhour was corrupted error, and I can not figure out why. I am trying to have a time entered and check it to make sure it is a good input. making the array bigger or smaller seems not to work. I have also added checks in and the output seems find until I get the error</p>
  
  <pre><code>void DEPARTURETIME(string&amp; szdepartureTime)
  {
  bool berror;
  char cdeparture[9];
  int nhour[2],
      nminute[2],
      nhourValue,
      nminuteValue;
  nhour[0] = 0;
  do
      {
          berror = false;
          system("CLS");
          cout &lt;&lt; "Enter departure time. (HH:DDAM/PM)" &lt;&lt; endl;
          cin &gt;&gt; cdeparture;
          cin.ignore();
          berror = ERRORCHECK();
          for (int i = 0; i &lt; 2 &amp;&amp; berror != true; i++)
              {
                  nhour[i] = CONVTOINT(cdeparture[i]);
              }
  //Beginning of testing hour for errors
          if (nhour[0] &gt; 1 &amp;&amp; berror != true)
              {
                  cout &lt;&lt; "Error, can not exceed 12 hours." &lt;&lt; endl;
                  system("pause");
                  berror = true;
              }
          else if (nhour[0] == 1)
              {
                  nhour[0] *= 10;
              }
          cout &lt;&lt; nhour[0] &lt;&lt; nhour[1] &lt;&lt; endl;
          nhourValue = nhour[0] + nhour[1];
          cout &lt;&lt; nhourValue &lt;&lt; endl;
          if (nhourValue &gt; 12 || nhourValue &lt;= 0 &amp;&amp; berror != true)
              {
                  cout &lt;&lt; "Error, can not exceed 12 hours and can not be 
  zero." &lt;&lt; endl;
                  system("pause");
                  berror = true;
              }
  //End of testing hour for errors
  //Beginning of testing for a colon
          if (cdeparture[2] != ':' &amp;&amp; berror != true)
              {
                  cout &lt;&lt; "Error, you need a colon inbetween hours and minutes." &lt;&lt; endl;
                  system("pause");
                  berror = true;
              }
  //End of testing for a colon
          for (int i = 3; i &lt; 5 &amp;&amp; berror != true; i++)
              {
                  nminute[i] = CONVTOINT(cdeparture[i]);
              }
  //Beginning of testing for minute errors
          if (nminute[3] &gt; 6 &amp;&amp; berror != true)
              {
                  cout &lt;&lt; "Error, minutes can not exceed 60." &lt;&lt; endl;
                  system("pause");
                  berror = true;
              }
          else if (nminute[3] &gt; 0 || berror != true)
              {
                  nminute[3] *= 10;
              }
          nminuteValue = nminute[3] + nminute[4];
          if (nminuteValue &gt; 60 &amp;&amp; berror != true)
              {
                  cout &lt;&lt; "Error, minutes can not exceed 60." &lt;&lt; endl;
                  system("pause");
                  berror = true;
              }
  //End of testing for minute errors
          cdeparture[5] = toupper(cdeparture[5]);
          cdeparture[6] = toupper(cdeparture[6]);
  //Beginning of testing for AM and PM errors
          if (cdeparture[5] != 'A' &amp;&amp; cdeparture[5] != 'P' || cdeparture[6] != 'M' &amp;&amp; berror != true)
              {
                  cout &lt;&lt; "Error, must have AM or PM." &lt;&lt; endl;
                  system("pause");
                  berror = true;
              }
      } while (berror != false);
  //End of testing for AM and PM errors
      for (int i = 0; i &lt; 7; i++)
          {
              szdepartureTime += cdeparture[i];
          }
  return;
  </code></pre>
  
  <p>}</p>
  
  <p>and this is the other function that is called</p>
  
  <pre><code>int CONVTOINT(char cchar)
  {
      int value = cchar - '0';
      if (value &lt; 0 || value &gt; 9)
          {
              cout &lt;&lt; "Error, Convertion failed" &lt;&lt; endl;
              system("pause");
              return 0;
          }
      return value;
  }
  </code></pre>