0

So I finally got the code working when it looks like this:

int k, l, m = 0;
    for (k = 0; k < d; k++)
    {
        for (l = 0; l < d; l++)
        {
            if (board[k][l] == m + 1 && board[d-1][d-1] == 0)
            {
                m++;
            }
        }
    }

My question is that I declared m as 0 and then in the if statement added one... If I just declare int m = 1 and then just say if board[k][l] == m instead of board[k][l] == m + 1 it no longer works. I cant for the life of me figure out why. Could anyone help me understand this? thanks!

0

Consider iterations other than the first , if m=1, does this line evaluate to true?

 if (board[k][l] == m + 1 && board[d-1][d-1] == 0)
| improve this answer | |
  • The thing I dont understand is: m = 1 if (board[k][l] == m && board[d-1][d-1] == 0) that wont work but m = 0 if (board[k][l] == m + 1 && board[d-1][d-1] == 0) that does work... isnt that the same as m = 1 if (board[k][l] == 1 && board[d-1][d-1] == 0) vs m = 0 if (board[k][l] == 0 + 1 && board[d-1][d-1] == 0) thanks! – Michael Apr 14 '16 at 16:46
  • I'm sorry about the typo in the original above, please see edit. I'm not sure what you mean by it works when m=0 if (board[k][l] == m + 1 && board[d-1][d-1] == 0). Consider iterations other than the first. Let's take the 2nd where k=0, l=1, m=1. Will board [d-l][d-l]==0, as it did in the first iteration when l=0? – ronga Apr 15 '16 at 3:13

You must log in to answer this question.

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