Calculating profit and score, if coordinates fall in a certain region of a field My function takes the values of the profit (function declared as fieldProfit) and the field score (function declared as fieldScore). If both are above 10, then you earn a badge, hence, innerbadge = 1.

But, there's also another condition that must be met: the field or (x, y) coordinates have to fall in the area depicted as the shaded in box that has a hole in the middle.  Here's the image:



I've written the code for it, and I just wanted to make sure that my logic/syntax is correct.

 int badgeInnerCircle(int x, int y) {
       double fprofit, fscore;
       int innerbadge;

       if ((x &gt;= 1 &amp;&amp; x &lt;= 20) &amp;&amp; (y &gt;= 1 &amp;&amp; y &lt;= 20)) {
          if (((x == 7 || x == 8) &amp;&amp; (y &gt;= 7 &amp;&amp; y &lt;= 14)) || ((x == 13 || x == 14)
             &amp;&amp; (y &gt;= 7 &amp;&amp; y &lt;= 14)) || ((x &gt;= 7 &amp;&amp; x &lt;= 14) &amp;&amp; (y == 7 || y == 8))
                || ((x &gt;= 7 &amp;&amp; x &lt;= 14) &amp;&amp; (y == 13 || y == 14))) {
             fprofit = fieldProfit(x, y);
             fscore = fieldScore(x, y);
             if (fprofit &gt;= 10 &amp;&amp; fscore &gt;= 10) {
                innerbadge = 1;
             }
             else {
                innerbadge = 0;
             }
          }
       }
       else {
          innerbadge = -1;
       }
       return innerbadge;
    }
I think we can all agree that that code is hard to read.  Rather than treating the dark shaded zone as the union of four rectangles, you would be better off treating it as a square with the centre excluded.

I've used a macro to reduce the verbosity.

In your code, when (x, y) falls in either of the white zones, you return an uninitialized value for innerbadge.  In those cases, the behaviour is undefined.

#define XY_IN_SQUARE(min, max) (((min) &lt;= x &amp;&amp; x &lt;= (max)) &amp;&amp; \
                                ((min) &lt;= y &amp;&amp; y &lt;= (max)))

int badgeInnerCircle(int x, int y) {
    if (XY_IN_SQUARE(9, 12)) {          /* In innermost white zone */
        return /* what? */;
    } else if (XY_IN_SQUARE(7, 14)) {   /* In dark grey zone */
        double fprofit = fieldProfit(x, y);
        double fscore = fieldScore(x, y);

        /* The following value will be either 1 or 0 */
        return fprofit &gt;= 10 &amp;&amp; fscore &gt;= 10;
    } else if (XY_IN_SQUARE(2, 19)) {   /* In outer white zone */
        return /* what? */;
    } else if (XY_IN_SQUARE(1, 20)) {   /* On yellow border */
        return /* what? */;
    } else {                            /* Outside yellow border */
        return -1;
    }
}