Tyler
Tyler

Reputation: 27

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++;
        }
      }
    }
  }
}

Upvotes: 2

Views: 361

Answers (2)

Adam Liss
Adam Liss

Reputation: 48320

Declaring double finalArray[600][0] means the array is 600 elements by 0 elements. I think you want the second dimension to be 1. Remember, you need to declare the number of rows and columns, but indices start at 0.

Upvotes: 1

Anand V
Anand V

Reputation: 124

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!

Upvotes: 1

Related Questions