I have this TicTacToe program that needs finishing. All the code is finished, but I'm getting runtime errors. It is printing out junk values from my array when they should be empty. I would love help please. This is due in a day and I've had 4 people working with me for 9 hours trying to get it finished.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//Player.h
#include <string>
#include "TTT.h"
usingnamespace std;
class Player {
private:
string name;
int playerNumber;
public:
Player(string tempName, int tempPlayerNumber);
int getIndex();
string getName();
void nextMove(TTT &object);
};
1 2 3 4 5 6 7 8 9 10 11 12
//TTT.h
usingnamespace std;
class TTT {
private:
char board[3][3];
public:
TTT();
void displayBoard();
bool setValue(int row, int column, int playerNumber);
int getStatus();
};
In TTT.cpp on line 9 you declare a variable with the same name as a private variable (board.) It would appear you're actually trying to initialize the data member, but you are not actually doing so.
Ok, you have to change TTT
TTT::TTT() {
const int SIZE = 3;
int board[SIZE][SIZE] = {};
//for(int i = 0; i < 3; i++) {
// for(int k = 0; k < 3; k++) {
// board[i][k] = 0;
// }
//}
}
to
TTT::TTT() {
row = 0;
column = 0;
int playerNumber = '\0';
for (int i = 0; i < 3; i++)
{
for (int k = 0; k < 3; k++)
{
board[i][k] = playerNumber;
}
}
}