Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I can\'t ge #include <iostream> #include <cstring> #include <cstdio> using names

ID: 3552987 • Letter: I

Question

I can't ge

#include <iostream>

#include <cstring>

#include <cstdio>

using namespace std;

char board[3][3];

int num_moves;

void print_board(void)

{

int row = 0;

cout << endl;

while(row < 3)

{

int col = 0;

while(col < 3)

{

cout << board[row][col] << " ";

col++;

}

cout << endl;

row++;

}

}

void clear_board(void)

{

int row = 0;

while(row < 3)

{

int col = 0;

while(col < 3)

{

board[row][col] = '.'; // empty char

col++;

}

row++;

}

num_moves = 0;

}

/* Returns 1 if game won and 0 otherwise. */

int evaluate()

{

if (((board[0][0] == board[0][1]) && (board[0][1] == board[0][2]) && board[0][0] != '.') || // first row

((board[1][0] == board[1][1]) && (board[1][1] == board[1][2]) && board[1][0] != '.') || // sec row

((board[2][0] == board[2][1]) && (board[2][1] == board[2][2]) && board[2][0] != '.') || // thrd row

((board[0][0] == board[1][0]) && (board[1][0] == board[2][0]) && board[0][0] != '.') || // first col

((board[0][1] == board[1][1]) && (board[1][1] == board[2][1]) && board[0][1] != '.') || // sec col

((board[0][2] == board[1][2]) && (board[1][2] == board[2][2]) && board[0][2] != '.') || // thrd col

((board[0][0] == board[1][1]) && (board[1][1] == board[2][2]) && board[0][0] != '.') || // left diagnol

((board[2][0] == board[1][1]) && (board[1][1] == board[0][2]) && board[2][0] != '.')) // right diagnol

return 1;

else

return 0;

}

int take_turn()

{

int r=-1, c=-1;

int i=1;

char mv;

int player=1;

player=(player%2)?1:2;

mv=(player==1) ? 'X': 'O';

cout << " Enter coordinates of your move (row col) : " << player << " : ";

cin >> r >> c;

while (!(r>-1 && r<3 && c>-1 && c<3) || board[r][c] != '.')

{

cout << "Invalid coordinates: Please try again (row col): ";

cin >> r >> c;

}

board[r][c] = mv;

num_moves++;

player++;

print_board();

if(evaluate() == 1)

{

cout << "Game won by " << player << endl;

return 1;

}

return 0;

}

int main()

{

int result;

cout << "Tic Tac Toe" << endl;

int player=1,i;

clear_board();

print_board();

player=(player%2?1:2);

while(num_moves < 9)

{

char p[20];

take_turn();

cout << " " << "Next Move" << endl ;

}

//char unused;

//scanf("%c ",&unused);

return 0;

}

t my program to advance from player to player 2

Explanation / Answer

have a look at my code..
here they are not allowing to enter more than 65000 characters..
thats why i am giving you a link..

https://ideone.com/0UJAoY

this is the running code.. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote