Design a program that allows two players to play a game of tic-tac-toe.  Use a two dimensional String array with three rows and three columns as the game board.  Each element of the array should be initialized with a asterisk (*).  The program should run a loop that does the following: Display the contents of the board array. Allows player 1 to select a location on the board for an X.  The program should ask the user to enter the row and column number.  Allows player 2 to select a location on the board for an O.  The program should ask the user to enter the row and column number. Determines whether a player has won or if a tie has occurred.  If a player has won, the program should declare that player the winner and end.  If a tie has occurred, the program should say so and end.    Player 1 wins when there are three X's in a row on the game board.  Player 2 wins when there are three O's in a row on the game board.  The winning X's or O's can appear in a row, in a column, or diagonally across the board.  A tie occurs when all of the locations on the board are full, but there is no winner.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question

 Design a program that allows two players to play a game of tic-tac-toe.  Use a two dimensional String array with three rows and three columns as the game board.  Each element of the array should be initialized with a asterisk (*).  The program should run a loop that does the following:

  1. Display the contents of the board array.
  2. Allows player 1 to select a location on the board for an X.  The program should ask the user to enter the row and column number. 
  3. Allows player 2 to select a location on the board for an O.  The program should ask the user to enter the row and column number.
  4. Determines whether a player has won or if a tie has occurred.  If a player has won, the program should declare that player the winner and end.  If a tie has occurred, the program should say so and end.   
  5. Player 1 wins when there are three X's in a row on the game board.  Player 2 wins when there are three O's in a row on the game board.  The winning X's or O's can appear in a row, in a column, or diagonally across the board.  A tie occurs when all of the locations on the board are full, but there is no winner.  
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning