1

My code is posted here: https://gist.github.com/themattmcguire/1ee1a683fe2e22ff1b7b4ef8cebe120b

My code correctly works on all the stock images, for all the functions (grayscale, sepia, reverse, and blur), however, the check50 is only giving me 7 out of 22 correct. I'm sure I built my code in a roundabout way, but I'm not sure why it's failing these checks since it achieves the desired function.

I'm not really sure where to start looking for issues, since the output comes out fine. Any help would be appreciated on this fellows!

These are the errors I receive when I run the code through the CS50 Check:

:) helpers.c exists

:) filter compiles

:) grayscale correctly filters single pixel with whole number average

:( grayscale correctly filters single pixel without whole number average expected "28 28 28\n", not "27 27 27\n"

:) grayscale leaves alone pixels that are already gray

:) grayscale correctly filters simple 3x3 image

:( grayscale correctly filters more complex 3x3 image expected "20 20 20\n50 5...", not "20 20 20\n50 5..."

:( grayscale correctly filters 4x4 image expected "20 20 20\n50 5...", not "20 20 20\n50 5..."

:( sepia correctly filters single pixel expected "56 50 39\n", not "55 49 38\n"

:( sepia correctly filters simple 3x3 image expected "100 89 69\n100...", not "100 88 69\n100..."

:( sepia correctly filters more complex 3x3 image expected "25 22 17\n66 5...", not "24 22 17\n65 5..."

:( sepia correctly filters 4x4 image expected "25 22 17\n66 5...", not "24 22 17\n65 5..."

:( reflect correctly filters 1x2 image expected "0 0 255\n255 0...", not "3 0 0\n0 0 255..."

:( reflect correctly filters 1x3 image expected "0 0 255\n0 255...", not "207 25 225\n0 ..."

:( reflect correctly filters image that is its own mirror image expected "255 0 0\n255 0...", not "0 255 0\n255 0..."

:( reflect correctly filters 3x3 image expected "70 80 90\n40 5...", not "110 130 140\n4..."

:( reflect correctly filters 4x4 image expected "100 110 120\n7...", not "110 130 140\n1..."

:( blur correctly filters middle pixel expected "127 140 149\n", not "126 140 149\n"

:) blur correctly filters pixel on edge

:) blur correctly filters pixel in corner

:( blur correctly filters 3x3 image expected "70 85 95\n80 9...", not "70 85 95\n80 9..."

:( blur correctly filters 4x4 image expected "70 85 95\n80 9...", not "70 85 95\n80 9..."

1

When doing operationns that could result in decimal point values it's not a good idea to work with 'int' values because the result's decimal point will be truncated. It's better to do the math with a type that can store decimal points and then rounded 'round()' when assigning it to a 'int' type. For reflection check for situations when you could be getting out of limits of the arrays in the for loops. I recommend to test the values of the variables using 'printf' inside the code in some points to check if you're getting the results you are looking for. Also 'debug50' is a great tool to stop the program and check every variable value at any point you want.

| improve this answer | |
  • Thanks, I'll try some of those to debug! – Matthew McGuire Apr 18 at 18:44
  • I did exactly what you suggested by calculating the values using floats instead of ints, and then using the round() function to bring it back to the proper int value. This fixed most of my problems. My reflect function had a completely different issue which I figured out on my own. Thanks for the help! – Matthew McGuire Apr 19 at 22:22

You must log in to answer this question.

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