dimanche 22 mars 2015

My program stops in the middle of its operation because it is unable to assign an element of a 2 dimensional array?

I was trying to make a tic tac toe program that allows two users to play tic tac toe. The program allows the users to decide, if they want to play, what symbols to represent themselves by, and which user will go first; however, the program does not allow the users to enter onto the playing board.


I ran the debugger tool in Codeblocks and found that the problem lies in the Input() function of my program. Below is where the input function is called in my program:



while (checkWin() != true && checkTie() != true)
{
input();
checkWin();
checkTie();
}


Here are the contents of the input() function that are important, the lines I believe are causing the problem are also indicated:



if (playerTurn == '1' && notFilled(in))
{
if (in == 1)
{
board[0][0] = player1Sym; //I think this line may be causing a problem.
}
else if (in == 2)
{
board[0][2] = player1Sym; //and this one
}
else if (in == 3)
{
board[0][4] = player1Sym; //and this one
}
else if (in == 4)
{
board[2][0] = player1Sym; //and this one
}
else if (in == 5)
{
board[2][2] = player1Sym; //and this one
}
else if (in == 6)
{
board[2][4] = player1Sym; //and this one
}
else if (in == 7)
{
board[4][0] = player1Sym; //and this one
}
else if (in == 8)
{
board[4][2] = player1Sym; //and this one
}
else if (in == 9)
{
board[4][4] = player1Sym; //and this one
}

playerTurn = '2';
}


If anyone was wondering, there is another else if statement in case playerTurn is equal to '2' that is basically a duplicate of the first if statement except for a few details. Thus, it is not necessary to post these lines.


Please help me to find the problem in this code.


Aucun commentaire:

Enregistrer un commentaire