This is the exercise I'm doing:
Write a two-player tic-tac-toe game, allowing two humans to play against each other; use
enums when possible to represent the values of the board.
But right now I'm more interested in using arrays in this tic-tac-toe program.
So here's the code I've came up so far:
Code:
#include <iostream>
#include <string>
using namespace std;
int board[3][3];
void startGAME();
string player1;
string player2;
int main ()
{
cout << "You're now playing tic tac toe. \n";
cout << "Player1 name: ";
getline (cin, player1);
cout << endl;
cout << "Player2 name: ";
getline (cin, player2 );
cout << endl;
cout << "Start game? y/n ";
string yesORno;
getline (cin, yesORno );
if (yesORno == "yes" )
{ startGAME(); }
else if (yesORno == "no" )
{
cout << "Exiting game... \n";
system ("pause");
return 0;
}
else
{ cout << "Invalid choice. \n"; }
system("pause");
return 0;
}
int board[3][3]
{
cout << [0][0] << "|" << [0][1] << "|" << [0][2] << endl;
cout << "_____"<< "|" << "_____"<< "|" << "_____"<< endl;
cout << [1][0] << "|" << [1][1] << "|" << [1][2] << endl;
cout << "_____"<< "|" << "_____"<< "|" << "_____"<< endl;
cout << [2][0] << "|" << [2][1] << "|" << [2][2] << endl;
}
void startGAME()
{
cout << "Player1 take O and Player2 take X. \n";
int turn, gameOVER(true), gameWIN, gameDRAW, row, column;
do
{
cout << "Player1 first. Choose which row and which column. \n";
board[3][3];
cout << "Row: ";
cin >> row;
cout << "Column: ";
cin >> column;
for ( row = 0 ; row < 3 ; row++)
{
for ( column = 0 ; column < 3 ; column++ )
{
board [row][column] = 'X';
}
}
}
while (!gameOVER);
}
I got this compiler error:
1>------ Build started: Project: 42, Configuration: Debug Win32 ------
1> 424.cpp
1>c:\users\user\documents\visual studio 2010\projects\42\42\424.cpp(52): error C2470: 'board' : looks like a function definition, but there is no parameter list; skipping apparent body
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========