0

I have finished the game of fifteen program. Yet, I still have two errors I don't understand about how my program should exit.

I think it is because of my won function which try to see if each slot of an array is equals to numbers from 0 to d*d.

:( 3x3.txt wins the 3x3 board
   \ expected an exit code of 0, not a prompt for input
:( 4x4.txt wins the 4x4 board
   \ expected an exit code of 0, not a prompt for input

Here is the code of won:

bool won(void)
{
    // We are going to see if each slot is sorted in the increeding maneer.
    bool gagné = false;
    for(int compteur_verif=0;compteur_verif>d*d;compteur_verif++){
        // increeding lines 
        for(int ligne = 0;ligne<d;ligne++){
            // increeding columns
            for (int colonne= 0;colonne<d;colonne++){
                // verifying slot by slot
                while(board[ligne][colonne]==compteur_verif){
                    gagné = true;
                }
            }
        }
    }
    if(gagné==true){
        return true;
    }
    return false;
}
1
  • This function is either returning true or false, so I assume that that the problem would be in main() at the time the program exits. Sep 30 '16 at 17:40
1

This error means that won() isn't working correctly. When won() returns false, it thinks that the game has not been won and causes a prompt for the next move.

Look at the for loop setup:

for(int compteur_verif=0;compteur_verif>d*d;compteur_verif++){

This for loop will never execute. compteur_verif is initialized as 0 and the test condition requires that compteur_verif must be greater than d*d for the loop to execute. So, you'll never win a game.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Thanks, it was actually the answer. So stupid... Yet, loop is now enters this loop at any time... I am looking forward to investigate this new issue... Oct 4 '16 at 16:23
-1

Actually, the check50 output says the problem is that you are prompting for user input interactively (as with get_int()) rather than getting the input from command-line arguments. So I'd start there.

Note that there may also be other problems in your code; I didn't check.

2
  • 1
    Nope, nothing to do with the problem. Sorry Matt.
    – Cliff B
    Sep 30 '16 at 21:48
  • No apology necessary. I earned that downvote fair and square -- I shouldn't answer questions without checking things first! Sep 30 '16 at 23:22

You must log in to answer this question.

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