Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 阵列周围的堆栈已损坏_C++_Arrays - Fatal编程技术网

C++ 阵列周围的堆栈已损坏

C++ 阵列周围的堆栈已损坏,c++,arrays,C++,Arrays,我正在使用Visual Studio 2015,但遇到了一个问题。运行时检查失败#2-变量“myArray”周围的堆栈已损坏。我不确定程序中的哪个位置可能会对我的数组造成某种损坏。但是,当我进行涉及操纵数组的计算时,有几个数字变成了0.0000,而不是原来的数字。有人能帮忙吗 #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() {

我正在使用Visual Studio 2015,但遇到了一个问题。运行时检查失败#2-变量“myArray”周围的堆栈已损坏。我不确定程序中的哪个位置可能会对我的数组造成某种损坏。但是,当我进行涉及操纵数组的计算时,有几个数字变成了0.0000,而不是原来的数字。有人能帮忙吗

#include <iostream>
#include <iomanip>
#include <cmath>
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 << "Enter in a value for the minimum x value: ";
   cin >> xmin;
   cout << "Enter in a value for the maximum x value: ";
   cin >> xmax;

   if (xmin < 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 << setw(15) << "x |" << setw(15) << "f(x)" << endl;
   cout << setw(32) << setfill('-') << " " << endl;
   cout << setfill(' ');

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

      if (myArray[i] <= minimum)
         minimum = myArray[i];
      if (myArray[i] > maximum)
         maximum = myArray[i];
   }

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

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


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

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

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

   system("pause");
   return 0;
}  
#包括
#包括
#包括
使用名称空间std;
int main()
{
双xmin,xmax;
常数积分=20;
常数双PI=3.1416;
双倍递增;
双量程,平均值;
双倍合计=0;
双myArray[点];
双倍数字=myArray[0];
双模式=数字;
整数计数=1;
int countMode=1;
cout>xmin;
cout>xmax;
if(xmin<0)
增量=(abs(xmin)+xmax)/点;
其他的
增量=(xmax-xmin)/点;
int i=0;
双x=xmin+增量*i;
双最小值=0.0572*cos(4.667*x)+0.0218*PI*cos(12.22*x);
双倍最大值=myArray[19];
库特
myArray
是一个20个双精度数组-
myArray[0]
myArray[19]

for (i = 0; i <= POINTS; i++)
{
    myArray[i] = 0.0572 * cos(4.667 * x) + 0.0218 * PI * cos(12.22 * x);
(i=0;i)的

myArray
是一个20个双精度数组-
myArray[0]
myArray[19]

for (i = 0; i <= POINTS; i++)
{
    myArray[i] = 0.0572 * cos(4.667 * x) + 0.0218 * PI * cos(12.22 * x);

for(i=0;我可以将代码缩减到当前大小的1/4左右,并隔离出问题所在吗?目前,您所拥有的是一个墙式代码,它为任何试图提供帮助的人提供了一个巨大的进入障碍,可能其中很多与手头的问题无关。(作为奖励,您甚至可以自己在过程中发现问题)
(int i=0;我可以将代码缩减到当前大小的1/4左右,并隔离出问题所在吗?目前为止,您拥有的是一个墙O’代码,它为任何试图提供帮助的人提供了巨大的进入壁垒,其中很多可能与手头的问题无关。(作为奖励,您甚至可以自己在过程中识别问题)
for(int i=0;i