title: CS50 - pset4 filter's blur function is just counting upwards
body: <p>I'm working on filter (less) in pset4, and I've got every other function fully checked out, but when I run check50 on this, I get the following responses for blur:</p>
  <pre><code>:( blur correctly filters middle pixel
      expected &quot;127 140 149\n&quot;, not &quot;120 140 150\n&quot;
  :( blur correctly filters pixel on edge
      expected &quot;80 95 105\n&quot;, not &quot;40 50 60\n&quot;
  :( blur correctly filters pixel in corner
      expected &quot;70 85 95\n&quot;, not &quot;10 20 30\n&quot;
  :( blur correctly filters 3x3 image
      expected &quot;70 85 95\n80 9...&quot;, not &quot;10 20 30\n40 5...&quot;
  :( blur correctly filters 4x4 image
      expected &quot;70 85 95\n80 9...&quot;, not &quot;10 20 30\n40 5...&quot;
  </code></pre>
  <p>That first one makes it look like I'm doing some sort of rounding error (although a very inconsistent one, rounding that first digit down and then the last digit up), but then the errors get stranger and stranger to me as the images get larger, until by the last array I'm generating:</p>
  <pre><code>10 20 30
  40 50 60
  70 80 90
  100 110 120
  110 130 140
  120 140 150
  130 150 160
  140 160 170
  195 204 213
  205 214 223
  225 234 243
  245 254 253
  50 28 90
  0 0 0
  255 255 255
  85 85 85
  </code></pre>
  <p>I'm not sure how I started doing that, but I don't like it at all. Could anyone give me advice as to what I'm doing wrong here? Thanks very much for your time. The code is below:</p>
  <pre><code>void blur(int height, int width, RGBTRIPLE image[height][width])
  {
      // copy the image
      // figure out blur data from the original picture and apply to the copy
      RGBTRIPLE tempArray[height][width];
      for (int i = 0; i &lt; height; i++)
      {
          for (int j = 0; j &lt; width; j++)
          {
              int validPixels = 0;
              // cycle through area around a pixel
              for (int blurRadiusX = -1; blurRadiusX &gt; 1; blurRadiusX++)
              {
                  for (int blurRadiusY = -1; blurRadiusY &gt; 1; blurRadiusY++)
                  {
                  // check area around pixels to see if it's at a valid location
                      if ((i + blurRadiusX &gt; 0) &amp;&amp; (i + blurRadiusX &lt; (height - 1)) &amp;&amp; (j + blurRadiusY &gt; 0) &amp;&amp; (j + blurRadiusY &lt; (width - 1)))
                      {
                          // an array adding all the values up, to be averaged out later
                          tempArray[i][j].rgbtRed = tempArray[i][j].rgbtRed + image[i + blurRadiusX][j + blurRadiusY].rgbtRed;
                          tempArray[i][j].rgbtGreen = tempArray[i][j].rgbtGreen + image[i + blurRadiusX][j + blurRadiusY].rgbtGreen;
                          tempArray[i][j].rgbtBlue = tempArray[i][j].rgbtBlue + image[i + blurRadiusX][j + blurRadiusY].rgbtBlue;
                          validPixels++;
                      }
                  }
              // if there are enough bytes to add these correctly, add and then divide by valid pixels
              // this should be applied to the image after tempArray is fully populated
              image[i][j].rgbtRed = round(tempArray[i][j].rgbtRed / validPixels * 1.00);
              image[i][j].rgbtGreen = round(tempArray[i][j].rgbtGreen / validPixels * 1.00);
              image[i][j].rgbtBlue = round(tempArray[i][j].rgbtBlue / validPixels * 1.00);
              }
          }
      }
      return;
  }
  </code></pre>
  <p>And here's CS50's page about the problem set: <a href="https://cs50.harvard.edu/x/2020/psets/4/filter/less/" rel="nofollow noreferrer">https://cs50.harvard.edu/x/2020/psets/4/filter/less/</a></p>