all checked right except two of them. it reflected the image correctly but I found two errors I can not understand them and how to solve it.

    void reflect(int height, int width, RGBTRIPLE image[height][width])
    int HW = width -1;
    HW = HW/2;
    for (int i = 0; i < height; i++)
        int n = 1;
        for (int j = 0; j < HW; j++)
            swap(&image[i][j], &image[i][width - n]);
void swap(RGBTRIPLE *a, RGBTRIPLE *b)
    RGBTRIPLE temp;
    RGBTRIPLE temp2;
    temp = *a;
    temp2 = *b;
    *a = temp2;
    *b = temp;

enter image description here

enter image description here


Remove the -1 from HW.

If the number of pixels per row is even, you need to swap half as many times.

If the number of pixels per row is odd, no need to swap the middle one with itself, so swap that number divided by two, and rounded down.

Integer division does exactly that, truncates the result. No -1 involved.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .