# Pset4 - Memory/reflection problem

So I've been on this reflection in pset4's memory problem for well over an hour and I can't seem to get the first column of height to reflect. Only the first column too, everything else reflects.

here's what I have so far

``````//this determines where to stop reflecting; shows the midpoint for both even and odd numbers
float mid = width / 2;
if (width % 2 == 1)
{
mid = round(width);
}

//From each pixel, starting from images[0][0], it will swap its RGB with the pixel on the opposite side of the row.
for (int a = 0; a < height; a++)
{
for (int b = 0; b < (int) mid; b++)
{

int temp = image[a][b].rgbtRed;
image[a][b].rgbtRed = image[a][width - b].rgbtRed;
image[a][width - b].rgbtRed = temp;

temp = image[a][b].rgbtBlue;
image[a][b].rgbtBlue = image[a][width - b].rgbtBlue;
image[a][width - b].rgbtBlue = temp;

temp = image[a][b].rgbtGreen;
image[a][b].rgbtGreen = image[a][width - b].rgbtGreen;
image[a][width - b].rgbtGreen = temp;

}
}
return;
``````

Think carefully about the values being used. Let's start with the first pixel, at 0,0, and that the image is 3x3 pixels.

``````image[a][b].rgbtRed = image[a][width - b].rgbtRed;
``````

Fill in the numbers for the first pixel being processed in the first pass of the loop.

``````image[0][0].rgbtRed = image[0][3 - 0].rgbtRed;
``````

This becomes:

``````image[0][0].rgbtRed = image[0][3].rgbtRed;
``````

Now, what's the y value for the rightmost pixel? Is it 3 or 2?

BTW, there's some code that you can remove. First, what happens when you do integer division? Is there a fractional part in the result? Second, think through how the mid point works in a 3 wide line vs 4 wide line of pixels. Do you really need to do anything more than divide width by 2? ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

• BTW, think about whether mid should be an int or a float. What happens to the test condition if mid, as a float, is just a hair smaller than the int value it is supposed to represent? (ie, 2.99999999997 vs. 3) May 28 at 5:00