1

I have been working on PSET4 and understood the code and the tasks fine. But my compilation does not change the image and I cannot figure out why it will not work for the life of me. I have checked and rechecked it a million times with other codes.

Thanks so much!

    void sepia(int height, int width, RGBTRIPLE image[height][width]) 
    {
         for (int i = 0; i < height; i++)
            {
            for (int j = 0; j < width; j++)
 
            {
              
       int sepiaRed=round(.393 * image[i][j].rgbtRed+ .769 * image[i][j].rgbtGreen+ .189 * image[i][j].rgbtBlue);
       int sepiaGreen=round(.349 * image[i][j].rgbtRed+ .686 * image[i][j].rgbtGreen+ .168 * image[i][j].rgbtBlue);
       int sepiaBlue=round(.272 * image[i][j].rgbtRed+ .534 * image[i][j].rgbtGreen+ .131 * image[i][j].rgbtBlue);

    if (sepiaRed > 255) 
    {
        image[i][j].rgbtRed = 255;
    }
    else
    {
        image[i][j].rgbtRed = sepiaRed;
    }
    
    if (sepiaGreen > 255)       
    {  
        image[i][j].rgbtGreen = 255;

    }   
    else
    {
        image[i][j].rgbtGreen = sepiaGreen;

    }
    if(sepiaBlue > 255)    
    {
        image[i][j].rgbtBlue = 255;
    }
    else
    {
        image[i][j].rgbtBlue=sepiaBlue;
    }
    
}
return;
}

}`

1 Answer 1

0

The problem is the return statement. It's inside the outer for loop, so only the first row gets processed.

This is why keeping indentations correct is important when writing code. Perhaps you should spend some quality time with style50? ;-)

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

3
  • Thanks, I have strived to pay attention to that, too, but often I am just too happy that the code is correct :) Why do we need to return anything anyway? Sometimes we do it, sometimes we do not
    – SirenLu
    Commented Dec 30, 2020 at 10:55
  • Best practice is to have a return statement at the end of the program. Technically, it's not necessary, since the compiler will insert it in the executable code if it's missing.
    – Cliff B
    Commented Dec 30, 2020 at 20:31
  • Thanks Cliff, Happy New Year!
    – SirenLu
    Commented Dec 31, 2020 at 14:11

You must log in to answer this question.

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