Search code examples
c++arraysfloating-point-exceptions

Why am I getting a floating point exception error?


I am a novice programmer, so please deal with me. I'm writing a program to analyze data. When I execute the program, I receive a "floating point exception" and I have no clue why. Here is the section of code where the error is originating from. From what I can tell, the if statement seems to be the problem but I do not understand why. Any help you can give is greatly appreciated!

double tArray[600][49];

void main() {
  double finalArray[600][0]
  double n = 0;
  int h = 0;
  try {
    for (int i = 0; i < 600; j++) {
      for (int j = 1; j < 16; j++) {
        h++;
        n = tArray[i][j * 3 - 1] - tArray[i][j * 3 - 2];
        double t = -30;
        if (n < t) {
          finalArray[i][0] = tArray[h][3 * j] - tArray[h + t][3 * j];
          h++;
        }
      }
    }
  }
}

Solution

  • Try declaring finalArray as:

    double finalArray[600][1];
    

    It appears that the original declaration did not allocate any space for the elements.

    If not try allocating only a single dimensional array like this:

    double finalArray[600];
    

    Hope this helps!