Stack around the array is corrupted
<p>I am using Visual Studios 2015, and I ran into a problem. Run-Time Check Failure #2 - Stack around the variable 'myArray' was corrupted. I am not sure where in the program that could cause some sort of corruption to my array. But when I did calculations involving manipulating the array, several numbers turned to 0.0000 instead of what they were originally. Could someone help?</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;cmath&gt;
using namespace std;

int main()
{
   double xmin, xmax;
   const int POINTS = 20;
   const double PI = 3.1416;
   double increments;
   double range, mean;
   double total = 0;
   double myArray[POINTS];
   double number = myArray[0];
   double mode = number;
   int count = 1;
   int countMode = 1;

   cout &lt;&lt; "Enter in a value for the minimum x value: ";
   cin &gt;&gt; xmin;
   cout &lt;&lt; "Enter in a value for the maximum x value: ";
   cin &gt;&gt; xmax;

   if (xmin &lt; 0)
      increments = (abs(xmin) + xmax) / POINTS;
   else
      increments = (xmax - xmin) / POINTS;

   int i = 0;
   double x = xmin + increments * i;
   double minimum = 0.0572 * cos(4.667 * x) + 0.0218 * PI * cos(12.22 * x);
   double maximum = myArray[19];

   cout &lt;&lt; setw(15) &lt;&lt; "x |" &lt;&lt; setw(15) &lt;&lt; "f(x)" &lt;&lt; endl;
   cout &lt;&lt; setw(32) &lt;&lt; setfill('-') &lt;&lt; " " &lt;&lt; endl;
   cout &lt;&lt; setfill(' ');

   for (i = 0; i &lt;= POINTS; i++)
   {
      myArray[i] = 0.0572 * cos(4.667 * x) + 0.0218 * PI * cos(12.22 * x);
      x = xmin + increments * i;
      cout &lt;&lt; fixed &lt;&lt; showpos &lt;&lt; setw(15) &lt;&lt; setprecision(2) &lt;&lt; x &lt;&lt;  setw(15) &lt;&lt; setprecision(4) &lt;&lt; myArray[i] &lt;&lt; endl;

      if (myArray[i] &lt;= minimum)
         minimum = myArray[i];
      if (myArray[i] &gt; maximum)
         maximum = myArray[i];
   }

   cout &lt;&lt; endl;
   range = maximum - minimum;
   for (int count = 0; count &lt;= POINTS; count++)
   {
      total += myArray[count];
   }
   mean = total / POINTS;

   int temp;
   bool swap;
   do
   {
      swap = false;
      for (int i = 0; i &lt; POINTS - 1; i++)
      {
         if (myArray[i] &gt; myArray[i + 1])
         {
            temp = myArray[i];
            myArray[i] = myArray[i + 1];
            myArray[i + 1] = temp;
            swap = true;
       }
      }
   } while (swap);


   for (int i = 0; i &lt;= POINTS; i++)
   {
      if (myArray[i] == number)
      {
         count++;
      }
      else
      {
         if (count &gt; countMode)
         {
            countMode = count;
            mode = number;
         }
         count = 1;
         number = myArray[i];
      }
   }

   cout &lt;&lt; "The maximum value is: " &lt;&lt; maximum &lt;&lt; endl;
   cout &lt;&lt; "The minimum value is: " &lt;&lt; minimum &lt;&lt; endl;
   cout &lt;&lt; "The range is: " &lt;&lt; range &lt;&lt; endl;
   cout &lt;&lt; "The mean value is: " &lt;&lt; mean &lt;&lt; endl;
   cout &lt;&lt; "The median value is: " &lt;&lt; (myArray[9] + myArray[10]) / 2  &lt;&lt;  endl;
   cout &lt;&lt; "The mode value is: " &lt;&lt; mode &lt;&lt; endl;

   for (i = 0; i &lt;= POINTS; i++)
      cout &lt;&lt; myArray[i] &lt;&lt; endl;

   system("pause");
   return 0;
}  
</code></pre>