Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need code for C++ program. Thanks Write a program that allows two players to play a game of tic-tac-toe. Use a two dimensional char

I need code for C++ program. Thanks

image text in transcribed

Write a program that allows two players to play a game of tic-tac-toe. Use a two dimensional char array with 3 rows and 3 columns as the gameBoard. Each element in the array should be initialized with an asterisk (*). The program should run a loop that does the following logic (some small variations may work for you if it still keeps the tic-tac-toe game working) 1. Displays the contents of the board array. Do this in a function called displayBoard(gameBoard) 2. Asks player 1 to select a location on the board for an X by specifying a row and column number. Do this in a function called playerTurn(gameBoard, 'X') . IMPORTANT: you can not let the user choose a location that is already marked with an X or an O -- the playerTurn function must check for this and loop until the plaer has chosen an unused location 3. Display again the contents of the board again (displayBoard(gameBoard)) 4. Create a function gameOver(gameBoard) that determines if either player has won (either a complete row, column or diagonal in one symbol X or O). If someone has won declare the winner and exit the game. If all spaces are used (no more *) then declare it a tie and exit the game 5. Asks player 2 to select a location on the board for an O by specifying a row and columrn number. Do this in a funciton called playerTurn(gameBoard, 'O'). Then make a call to display the updated gameBoard by calling displayBoard(gameBoard) 6. Call again the function gameOver(gameBoard) .. LOOP--- If no winner and morespaces LOOP to #2

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

Identify four applications of HRM to healthcare organizations.

Answered: 1 week ago