practice: tic-tac-toe
Write a two-player Tic-Tac-Toe game that:
- makes sure each space chosen for an 'X' or 'O' is empty
- detects when the game is over
- has a menu that shows up after each match to ask whether to play again
- keeps track of the number of wins, draws, and losses, displaying these between each match
Feel free to use the code below or make any changes to it.
#include <iostream>
using namespace std;
void print(char marks[]);
int main()
{
char marks[9] = { ' ' }; // this array will hold the Xs and Os
/*
Here's part of a way to detect whether a player has won:
if (marks[0] + marks[1] + marks[2] == 'X' * 3)
// then player X won
*/
}
void print(char marks[])
{
cout << "\n\n\n | |"
<< "\n " << marks[6] << " | " << marks[7] << " | " << marks[8]
<< "\n -----------"
<< "\n | |"
<< "\n " << marks[3] << " | " << marks[4] << " | " << marks[5]
<< "\n | |"
<< "\n -----------"
<< "\n " << marks[0] << " | " << marks[1] << " | " << marks[2]
<< "\n | |";
}