0

I've been stuck on this project for a while... I looked at other people's questions but still cannot find our where I did wrong. Can someone help me see where the bug is...

void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE copy[height][width];
    for (int h = 0; h < height; h++)
    {
        for (int w = 0; w < width; w++)
        {
            copy[h][w] = image[h][w];
        }
    }

    int avgB, avgG, avgR;
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            //i = 0
            if (i == 0)
            {
                if (j == 0)
                {
                    image[0][j].rgbtBlue = round((copy[0][j].rgbtBlue + copy[0][j + 1].rgbtBlue + copy[1][j].rgbtBlue + copy[1][j + 1].rgbtBlue) / 4.0);
                    image[0][j].rgbtGreen = round((copy[0][j].rgbtGreen + copy[0][j + 1].rgbtGreen + copy[1][j].rgbtGreen + copy[1][j + 1].rgbtGreen) /
                                                  4.0);
                    image[0][j].rgbtRed = round((copy[0][j].rgbtRed + copy[0][j + 1].rgbtRed + copy[1][j].rgbtRed + copy[1][j + 1].rgbtRed) / 4.0);
                }
                else if (j == (width - 1))
                {
                    image[0][j].rgbtBlue = round((copy[0][j - 1].rgbtBlue + copy[0][j].rgbtBlue + copy[1][j - 1].rgbtBlue + copy[1][j].rgbtBlue) / 4.0);
                    image[0][j].rgbtGreen = round((copy[0][j - 1].rgbtGreen + copy[0][j].rgbtGreen + copy[1][j - 1].rgbtGreen + copy[1][j].rgbtGreen) /
                                                  4.0);
                    image[0][j].rgbtRed = round((copy[0][j - 1].rgbtRed + copy[0][j].rgbtRed + copy[1][j - 1].rgbtRed + copy[1][j].rgbtRed) / 4.0);
                }
                else
                {
                    image[0][j].rgbtBlue = round((copy[i][j - 1].rgbtBlue + copy[i][j].rgbtBlue + copy[i][j + 1].rgbtBlue + copy[i + 1][j - 1].rgbtBlue
                                                  + copy[i + 1][j].rgbtBlue + copy[i + 1][j + 1].rgbtBlue) / 6.0);
                    image[0][j].rgbtGreen = round((copy[i][j - 1].rgbtGreen + copy[i][j].rgbtGreen + copy[i][j + 1].rgbtGreen + copy[i + 1][j -
                                                   1].rgbtGreen + copy[i + 1][j].rgbtGreen + copy[i + 1][j + 1].rgbtGreen) / 6.0);
                    image[0][j].rgbtRed = round((copy[i][j - 1].rgbtRed + copy[i][j].rgbtRed + copy[i][j + 1].rgbtRed + copy[i + 1][j - 1].rgbtRed +
                                                 copy[i + 1][j].rgbtRed + copy[i + 1][j + 1].rgbtRed) / 6.0);
                }
            }

            if (j == 0 && i != 0)
            {
                image[i][j].rgbtBlue = round((copy[i - 1][j].rgbtBlue + copy[i - 1][j + 1].rgbtBlue + copy[i][j].rgbtBlue + copy[i][j + 1].rgbtBlue
                                              + copy[i + 1][j].rgbtBlue + copy[i + 1][j + 1].rgbtBlue) / 6.0);
                image[i][j].rgbtGreen = round((copy[i - 1][j].rgbtGreen + copy[i - 1][j + 1].rgbtGreen + copy[i][j].rgbtGreen + copy[i][j +
                                               1].rgbtGreen + copy[i + 1][j].rgbtGreen + copy[i + 1][j + 1].rgbtGreen) / 6.0);
                image[i][j].rgbtRed = round((copy[i - 1][j].rgbtRed + copy[i - 1][j + 1].rgbtRed + copy[i][j].rgbtRed + copy[i][j + 1].rgbtRed
                                             + copy[i + 1][j].rgbtRed + copy[i + 1][j + 1].rgbtRed) / 6.0);
            }
            else if (j == (width - 1) && i != 0)
            {
                image[i][j].rgbtBlue = round((copy[i - 1][j - 1].rgbtBlue + copy[i - 1][j].rgbtBlue + copy[i][j - 1].rgbtBlue + copy[i][j].rgbtBlue
                                              + copy[i + 1][j - 1].rgbtBlue + copy[i + 1][j].rgbtBlue) / 6.0);
                image[i][j].rgbtGreen = round((copy[i - 1][j - 1].rgbtGreen + copy[i - 1][j].rgbtGreen + copy[i][j - 1].rgbtGreen +
                                               copy[i][j].rgbtGreen + copy[i + 1][j - 1].rgbtGreen + copy[i + 1][j].rgbtGreen) / 6.0);
                image[i][j].rgbtRed = round((copy[i - 1][j - 1].rgbtRed + copy[i - 1][j].rgbtRed + copy[i][j - 1].rgbtRed + copy[i][j].rgbtRed
                                             + copy[i + 1][j - 1].rgbtRed + copy[i + 1][j].rgbtRed) / 6.0);
            }
            else if (i == (height - 1))
            {
                if (j == 0)
                {
                    image[i][j].rgbtBlue = round((copy[i][j - 1].rgbtBlue + copy[i][j].rgbtBlue + copy[i + 1][j - 1].rgbtBlue + copy[i +
                                                  1][j].rgbtBlue) / 4.0);
                    image[i][j].rgbtGreen = round((copy[i][j - 1].rgbtGreen + copy[i][j].rgbtGreen + copy[i + 1][j - 1].rgbtGreen + copy[i +
                                                   1][j].rgbtGreen) / 4.0);
                    image[i][j].rgbtRed = round((copy[i][j - 1].rgbtRed + copy[i][j].rgbtRed + copy[i + 1][j - 1].rgbtRed + copy[i + 1][j].rgbtRed) /
                                                4.0);
                }
                else if (j == (width - 1))
                {
                    image[i][j].rgbtBlue = round((copy[i][j].rgbtBlue + copy[i][j + 1].rgbtBlue + copy[i + 1][j].rgbtBlue + copy[i +
                                                  1][j + 1].rgbtBlue) / 4.0);
                    image[i][j].rgbtGreen = round((copy[i][j].rgbtGreen + copy[i][j + 1].rgbtGreen + copy[i + 1][j].rgbtGreen + copy[i +
                                                   1][j + 1].rgbtGreen) / 4.0);
                    image[i][j].rgbtRed = round((copy[i][j].rgbtRed + copy[i][j + 1].rgbtRed + copy[i + 1][j].rgbtRed + copy[i + 1][j + 1].rgbtRed) /
                                                4.0);
                }
                else
                {
                    image[i][j].rgbtBlue = round((copy[i][j - 1].rgbtBlue + copy[i][j].rgbtBlue + copy[i][j + 1].rgbtBlue + copy[i + 1][j - 1].rgbtBlue
                                                  + copy[i + 1][j].rgbtBlue + copy[i + 1][j + 1].rgbtBlue) / 6.0);
                    image[i][j].rgbtGreen = round((copy[i][j - 1].rgbtGreen + copy[i][j].rgbtGreen + copy[i][j + 1].rgbtGreen + copy[i + 1][j -
                                                   1].rgbtGreen + copy[i + 1][j].rgbtGreen + copy[i + 1][j + 1].rgbtGreen) / 6.0);
                    image[i][j].rgbtRed = round((copy[i][j - 1].rgbtRed + copy[i][j].rgbtRed + copy[i][j + 1].rgbtRed + copy[i + 1][j - 1].rgbtRed
                                                 + copy[i + 1][j].rgbtRed + copy[i + 1][j + 1].rgbtRed) / 6.0);
                }
            }
            else
            {
                //General part
                avgB = (copy[i - 1][j - 1].rgbtBlue + copy[i - 1][j].rgbtBlue + copy[i - 1][j + 1].rgbtBlue + copy[i][j - 1].rgbtBlue
                        + copy[i][j].rgbtBlue + copy[i][j + 1].rgbtBlue + copy[i + 1][j - 1].rgbtBlue + copy[i + 1][j].rgbtBlue + copy[i + 1][j +
                                1].rgbtBlue) / 9.0;
                avgG = (copy[i - 1][j - 1].rgbtGreen + copy[i - 1][j].rgbtGreen + copy[i - 1][j + 1].rgbtGreen + copy[i][j - 1].rgbtGreen
                        + copy[i][j].rgbtGreen + copy[i][j + 1].rgbtGreen + copy[i + 1][j - 1].rgbtGreen + copy[i + 1][j].rgbtGreen + copy[i + 1][j +
                                1].rgbtGreen) / 9.0;
                avgR = (copy[i - 1][j - 1].rgbtRed + copy[i - 1][j].rgbtRed + copy[i - 1][j + 1].rgbtRed + copy[i][j - 1].rgbtRed
                        + copy[i][j].rgbtRed + copy[i][j + 1].rgbtRed + copy[i + 1][j - 1].rgbtRed + copy[i + 1][j].rgbtRed + copy[i + 1][j + 1].rgbtRed) /
                        9.0;
                image[i][j].rgbtBlue = round(avgB);
                image[i][j].rgbtGreen = round(avgG);
                image[i][j].rgbtRed = round(avgR);
            }
        }
    }
    return;
}

A link to check50: https://submit.cs50.io/check50/f9ead9f49b6c45a8deb2c6c3f88e37ae010b4803

Been stuck for a while, really appreciate your help :)

You must log in to answer this question.

Browse other questions tagged .