title: CS 50 Edges filter
body: <p>Could someone tell me where in my code I made a mistake? The values are failing check50. The loops seem to be correct, I really can't tell where the problem is.</p>
  <p>I've looked at <a href="https://medium.com/swlh/cs50-pset-4-filter-8cbf734b0dbc" rel="nofollow noreferrer">https://medium.com/swlh/cs50-pset-4-filter-8cbf734b0dbc</a> and the code seems pretty much the same...</p>
  <p>Thank you so much!</p>
  <p><a href="https://pastebin.com/MkZPFbEK" rel="nofollow noreferrer">https://pastebin.com/MkZPFbEK</a></p>
  <pre><code>void edges(int height, int width, RGBTRIPLE image[height][width])
  {
  // for pixels at the border, treat value as B.G.R value as 0
  // compute gx and gy for each value of B, G, R
  // square root of gx and gy squared
   
      RGBTRIPLE tempstore[height][width];
   
      int Gx[3][3] = {
                      {-1, 0 , 1},
                      {-2, 0 , 2},
                      {-1, 0 , 1}
                      };
   
      int Gy[3][3] = {
                      {-2, -1 , -1},
                      {0, 0 , 0},
                      {2, -1 , 1}
                      };
   
   
      // for each row
      for (int i = 0; i &lt; height; i = i + 1)
          {
              // for each column
              for (int j = 0; j &lt; width; j = j + 1)
              {
                  // float horvalueB=0;
                  // float horvalueG=0;
                  // float horvalueR=0;
   
                  // float vertvalueB=0;
                  // float vertvalueG=0;
                  // float vertvalueR=0;
                  float sumhorB=0;
                  float sumhorG=0;
                  float sumhorR=0;
   
                  float sumvertB=0;
                  float sumvertG=0;
                  float sumvertR=0;
   
                  // check if height of neighbor cell
                  for (int k = -1; k &lt;= 1; k = k + 1)
                  {
                          for (int l = -1; l &lt;= 1; l = l + 1)
                          {
                             int htcheck = i + k;
                             int wdcheck = j + l;
                              // check if height of neighbor cell is within bounds
                              if (((htcheck) &gt;= 0) &amp;&amp; ((htcheck) &lt; height))
                              {
                                  // check if width of neighbor cell is within bounds
                                  if (((wdcheck) &gt;= 0) &amp;&amp; ((wdcheck) &lt; width))
                                  {
                                      sumhorB += image[htcheck][wdcheck].rgbtBlue * Gx[k+1][l+1];
                                      sumhorG += image[htcheck][wdcheck].rgbtGreen * Gx[k+1][l+1];
                                      sumhorR += image[htcheck][wdcheck].rgbtRed * Gx[k+1][l+1];
   
                                      sumvertB += image[htcheck][wdcheck].rgbtBlue * Gy[k+1][l+1];
                                      sumvertG += image[htcheck][wdcheck].rgbtGreen * Gy[k+1][l+1];
                                      sumvertR += image[htcheck][wdcheck].rgbtRed * Gy[k+1][l+1];
   
                                      // sumhorB = sumhorB + horvalueB;
                                      // sumhorG = sumhorG + horvalueG;
                                      // sumhorR = sumhorR + horvalueR;
   
                                      // sumvertB = sumvertB + vertvalueB;
                                      // sumvertG = sumvertG + vertvalueG;
                                      // sumvertR = sumvertR + vertvalueR;
                              }
                          }
                      }
                  }
                  int blue = round(sqrt( sumhorB*sumhorB + sumvertB*sumhorB ));
                  int green = round(sqrt( sumhorG*sumhorG + sumvertG*sumhorG ));
                  int red = round(sqrt( sumhorR*sumhorR + sumvertR*sumhorR ));
   
                  // Cap at 255
                  if (red &gt; 255)
                  {
                      red = 255;
                  }
                  if (green &gt; 255)
                  {
                      green = 255;
                  }
                  if (blue &gt; 255)
                  {
                      blue = 255;
                  }            // Assign new values to pixels
                  tempstore[i][j].rgbtRed = red;
                  tempstore[i][j].rgbtGreen = green;
                  tempstore[i][j].rgbtBlue = blue;
   
              }
          }
   
      for (int i = 0; i &lt; height; i = i + 1)
      {
          for (int j = 0; j &lt; width; j = j + 1)
          {
              image[i][j].rgbtBlue = tempstore[i][j].rgbtBlue;
              image[i][j].rgbtGreen = tempstore[i][j].rgbtGreen;
              image[i][j].rgbtRed = tempstore[i][j].rgbtRed;
          }
      }
   
      return;
  }
  </code></pre>