Below is the code that generated the error message. From what i can tell some part of this created a [j] value that was larger than the width.
My thoughts on this problem was:
With a hypothetical width of 300, 150 would be the middle point. And to the distance of [p] from the middle would be the int 'distance'. The formula j = ((-distance from middle * 2) + 1) is my way of moving j to its opposite side from the middle point. If j > half it would be moved backwards that many places from the middle and, If j < half it would be moved forward that many places from the middle.
Where is the error in this logic? Might it be the formula for generating 'distance' or in the way the code is written? It compiles fine, but doesn't execute.
void reflect(int height, int width, RGBTRIPLE image[height][width]) { for( int i = 0; i < height; i++) { for( int j = 0; j < width; j++) { float x = (width / 2); int half = round(x); int distance = ( half - (j - 1) * 2 ) - 1;
// Width is an even number
// If its larger than the half way point the number increases by two for every increment away.
// So... j = ((-distance from middle * 2) + 1)
// how do we find the number away from the middle.
// we know J and width
if (j == half)
{
image[i][j] = image[i][j];
}
if (j > half)
{
image[i][j] = image[i][j - distance];
}
// j = ((distance from middle * 2) - 1)
if (j < half)
{
image[i][j]= image[i][j + distance];
}
}
}
return;
}