0% found this document useful (0 votes)
2 views

Document_(4)[1]

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Document_(4)[1]

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

//Tic Tac Toe Game in C++

//Importing the inbuild libraries in CPP

#include <iostream>

#include <stdlib.h>

using namespace std;

//Array for the board

char board[3][3] = {{'1','2','3'},{'4','5','6'},{'7','8','9'}};

//Variable Declaration

int choice;

int row,column;

char turn = 'X';

bool draw = false;

//Function to show the current status of the gaming board

void display_board(){

//Rander Game Board LAYOUT

cout<<"PLAYER - 1 [X]t PLAYER - 2 [O]nn";

cout<<"tt | | n";

cout<<"tt "<<board[0][0]<<" | "<<board[0][1]<<" | "<<board[0][2]<<" n";

cout<<"tt_____|_____|_____n";

cout<<"tt | | n";

cout<<"tt "<<board[1][0]<<" | "<<board[1][1]<<" | "<<board[1][2]<<" n";

cout<<"tt_____|_____|_____n";

cout<<"tt | | n";

cout<<"tt "<<board[2][0]<<" | "<<board[2][1]<<" | "<<board[2][2]<<" n";


cout<<"tt | | n";

//Function to get the player input and update the board

void player_turn(){

if(turn == 'X'){

cout<<"ntPlayer - 1 [X] turn : ";

else if(turn == 'O'){

cout<<"ntPlayer - 2 [O] turn : ";

//Taking input from user

//updating the board according to choice and reassigning the turn Start

cin>> choice;

//switch case to get which row and column will be update

switch(choice){

case 1: row=0; column=0; break;

case 2: row=0; column=1; break;

case 3: row=0; column=2; break;

case 4: row=1; column=0; break;

You might also like