Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone add the main function to the code it keeps giving me error undefined winmain@16 here's the code: #include #include #include #include using namespace

can someone add the main function to the code it keeps giving me error undefined winmain@16

here's the code:

#include

#include

#include

#include

using namespace std;

enum status { WIN, DRAW, CONTINUE };

class ticTacToe

{

public:

void play();

private:

void displayBoard() const;

bool isValidMove(int row, int col) const;

bool getXOMove(char playerSymbol);

status gameStatus();

char board[3][3] = { {' ', ' ', ' '},

{' ', ' ', ' '},

{' ', ' ', ' '} };

int noOfMoves = 0;

};

void ticTacToe::play()

{

srand(time(0));

bool done = false;

char player;

if (rand() % 2 == 0) {

player = 'X';

}

else {

player = 'O';

}

displayBoard();

while (!done) {

done = getXOMove(player);

if (player == 'X') {

player = 'O';

}

else {

player = 'X';

}

}

}

void ticTacToe::displayBoard() const

{

cout << setw(3) << "1" << setw(3) << "2" << setw(3) << "3" << endl;

for (int row = 0; row < 3; row++) {

cout << setw(3) << row + 1;

for (int col = 0; col < 3; col++) {

cout << setw(3) << board[row][col];

}

cout << endl;

}

cout << endl;

}

bool ticTacToe::isValidMove(int row, int col) const

{

if (row < 0 || row > 2 || col < 0 || col > 2) {

return false;

}

if (board[row][col] != ' ') {

return false;

}

return true;

}

bool ticTacToe::getXOMove(char playerSymbol)

{

int row, col;

cout << "Player " << playerSymbol << ", enter your move (row column): ";

cin >> row >> col;

row--;

col--;

if (!isValidMove(row, col)) {

cout << "Invalid move. Please try again." << endl;

return false;

}

board[row][col] = playerSymbol;

noOfMoves++;

displayBoard();

status gameStatus = this->gameStatus();

if (gameStatus == WIN) {

cout << "Player " << playerSymbol << " wins!" << endl;

return true;

}

else if (gameStatus == DRAW) {

cout << "Game is a draw." << endl;

return true;

}

return false;

}

status ticTacToe::gameStatus()

{

for (int row = 0; row < 3; row++) {

if (board[row][0] != ' ' && board[row][0] == board[row][1] && board[row][1] == board[row][2]) {

return WIN;

}

}

for (int col = 0; col < 3; col++) {

if (board[0][col] != ' ' && board[0][col] == board[1][col] && board[1][col] == board[2][col]) {

return WIN;

}

}

if (board[0][0] != ' ' && board[0][0] == board[1][1] && board[1][1] == board[2][2]) {

return WIN;

}

if (board[2][0] != ' ' && board[2][0] == board[1][1] && board[1][1] == board[0][2]) {

return WIN;

}

if (noOfMoves == 9) {

return DRAW;

}

return CONTINUE;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

Azure Analytics is a suite made up of which three tools?

Answered: 1 week ago