0

Though my program fifteen.c/pset3 compiles with the int,draw,move function but the tiles are not moving at all. Here's my code as well the output.Kindly check and any suggestions will be appreciated. Stuck in for long, Plse help! Unecessary part of the code is removed.init , draw function are not there in the code as they are working well.

0

Could you show the whole code of main?

What I see is:

  1. you declare a lot of functions

  2. you define a lot of functions

  3. you never call any of this nice functions

  4. what really works is:

    int main(int argc, string argv[])
    { //functions of main including prompt for tile and d
    // success
    return 0;
    }
    

So, your code (as you show it here) does nothing just return 0.

PS. And yes, your code is TOO long for this task

| improve this answer | |
0

So, you call your functions. Great. Let's check the logic. Below code, as far as I understand, is supposed to return the column where tile is.

for(int i = 0; i < d; i++)
{   
for(int j = 0; j < d; j++)
{   
    if(tile == board[i][j])
    {
        return tc;
    }
    tc++;
}
tc -= d;
}
return 0;

But it doesn't do what it is assumed to do. Suppose that tile is in board[0][2], that is column 2. But the function returns tc = 0.

It looks like that your logic for rows is fine, but not for columns. One of the solutions is to switch i and j in the loop.

However, I would, if I can, advise you to make it a bit easier. If you would find the tile in board[i][j], does it mean that tr = i amd tc =j?

| improve this answer | |
  • Hey! thanks for the response but I had been making mistakes over variable scope and seemed to have fixed that by taking the help of global and local variables properly.Thanks again for the help! – sk.76 Jun 19 '17 at 17:51

You must log in to answer this question.

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