problem with functions

I am writing a program to run a tictactoe game but cant seem to figure this out
having trouble with my occupysquare function and the other two being illegal when calling
here is the code
implementation:
#include <iostream>

#include <cstdlib>

#include <iomanip>

#include <cmath>

#include <ctime>

#include "ttt.h"

using namespace std;

//Variables Declared
size_t x;
size_t y;
enum CheckForWinner { WIN };
enum IsScratch { CONTINUE, SCRATCH };
char Player;


TicTacToe::TicTacToe ()
{
InitializeBoard ();
}

void TicTacToe::InitializeBoard() //initialize the borad to blank spaces
{

for ( int a = 0; rows_< 3; a++)

for ( int b = 0; cols_< 3; b++)

board[a] [b] = ' ';


}


void TicTacToe::PrintBoard()
{
cout << " 0 1 2\n\n";

for ( int r = 0; r < 3; ++r )
{
cout << r;

for ( int c = 0; c < 3; ++c )
{
cout << setw( 3 ) << static_cast< char > ( board[ r ][ c ] );

if ( c != 2 )

cout << " |";

} // end for

if ( r != 2 )

cout << "\n ____|____|____\n | | \n";

} // end for

cout << "\n\n";

} //end printboard




bool TicTacToe::OccupySquare (size_t x, size_t y, char value)
{
PrintBoard();

IsValidLocation(x, y);

while ( true )
{
if (Player ( 'X' ) )
break;
else if (Player ( 'O' ) )
break;
}



bool TicTacToe::IsValidLocation(size_t x, size_t y)
{

if (x > 2 || x < 0 || y > 2 || y < 0)
{
return false;
}

if (board [x][y] != ' ')
{
return false;
}

if (x < 3 && x >= 0 && y < 3 && y >= 0)
{
return true;
}
if (board[x][y] = ' ')
{
return true;
}

}

char TicTacToe::CheckForWinner()
{


// check for a win on diagonals
if ( board[ 0 ][ 0 ] != ' ' && board[ 0 ][ 0 ] == board[ 1 ][ 1 ] &&
board[ 0 ][ 0 ] == board[ 2 ][ 2 ] )
{
return WIN;
}
else if ( board[ 2 ][ 0 ] != ' ' && board[ 2 ][ 0 ] ==
board[ 1 ][ 1 ] && board[ 2 ][ 0 ] == board[ 0 ][ 2 ] )
{
return WIN;
}
// check for win in rows
for ( int a = 0; a < 3; ++a )

if ( board[ a ][ 0 ] != ' ' && board[ a ][ 0 ] ==
board[ a ][ 1 ] && board[ a ][ 0 ] == board[ a ][ 2 ] )
{
return WIN;
}
// check for win in columns
for ( int a = 0; a < 3; ++a )

if ( board[ 0 ][ a ] != ' ' && board[ 0 ][ a ] ==
board[ 1 ][ a ] && board[ 0 ][ a ] == board[ 2 ][ a ] )
{
return WIN;
}
}// end to check for winner

bool TicTacToe::IsScratch()
{
// check for a completed game
for ( int r = 0; r < 3; ++r )

for ( int c = 0; c < 3; ++c )

if ( board[ r ][ c ] == ' ' )

return CONTINUE; // game is not finished

return SCRATCH; // game is a Scratch
}

}

driver:


#include <cstdlib>

#include <ctime>
#include <iostream>
#include <cmath>

#include <string>

#include "ttt.h"


using namespace std;

int main ()
{

//Variables Declared
// int NumberOfPlayers;
// char Player;
// char player;
// char PlayAgainAnswer;
size_t x;
size_t y;
enum CheckForWinner { WIN };
enum IsScratch { CONTINUE, SCRATCH };


TicTacToe myttt;
do
{
//Variables Declared inside the do loop
int NumberOfPlayers;
int Selection;
char Player;
int symbol;

// char XMove;
// char OMove;
// char X;
// char O;
// char player;
// char PlayAgainAnswer;
char Winner;
char XoStatus;
int board [ 3 ][ 3 ];
bool MyOccupySquare;




//Print out instructions

cout <<endl;
cout <<endl;
cout << "****** Welcome to Tic-Tac-Toe ******"<<endl;
cout << "********************************************************************"<<endl;
cout << "** **"<<endl;
cout << "** Instructions - You will be asked for how many players: **"<<endl;
cout << "** **"<<endl;
cout << "** Entering a 0 - two computer players **"<<endl;
cout << "** **"<<endl;
cout << "** Entering a 1 - human vs computer **"<<endl;
cout << "** **"<<endl;
cout << "** Entering a 2 - two human players **"<<endl;
cout << "** **"<<endl;
cout << "** Make your move known by entering coordinates, 0 - 2. **"<<endl;
cout << " "<<endl;

cout <<endl;



cout << "How many players will be playing? ";
cin >> NumberOfPlayers;

srand( (unsigned)time (0));

Selection = 1 + rand()% 2; //Assigning which player is X and O

if (Selection == 1)
{
Player = 'X';

}
else if (Selection == 2)
{
Player = 'O';


}



if (NumberOfPlayers == 0) //two computer players
{
cout<< "No Human Players, Computer vs Computer! " << endl;
cout<< endl;
cout << Player << "Will go first" << endl;
};
// do
// {

myttt.PrintBoard();

cout <<Player <<"'s turn" << endl;

//do
//{
x = 0 + rand() % 2;
y = 0 + rand() % 2;

cout <<Player << " selected " << x << y << endl;

myttt.OccupySquare(x,y, Player);

if (myttt.OccupySquare(x, y, Player) == false)
{
cout << "Error! Invalid Selection!" << endl;
}

Winner = myttt.CheckForWinner();

MyOccupySquare = myttt.OccupySquare(x,y,Player);


// }while (!MyOccupySquare );

board [ x ][ y] = symbol;

myttt.PrintBoard();
XoStatus = Winner;

if (XoStatus == WIN)
{
cout << "Player " << static_cast< char > ( symbol ) << " wins!\n";
return true;
} //end if


else if (XoStatus == SCRATCH )
{
cout << "Game is a Scratch.\n";
return true;
}// end else if

else

return false;

//}while (!MyOccupySquare );




// }while (1 == 1); //end of Computer Players


if (NumberOfPlayers == 2) //two human players
{
cout<< endl;
cout<< "Human vs Human" << endl;
cout<< endl;
}


do
{
myttt.PrintBoard();

cout << Player << "'s turn. " << static_cast< char >(symbol)<<endl;

cout << " Enter your square coordinates: "<< endl;
cin >> x >> y;

bool MyOccupySquare = myttt.OccupySquare(x,y,Player);

}while (!MyOccupySquare );

board [ x ][ y] = symbol;

myttt.PrintBoard();
XoStatus = Winner;

if (XoStatus == WIN)
{
cout << "Player " << static_cast< char > ( symbol ) << " wins!\n";
return true;
} //end if


else if (XoStatus == SCRATCH )
{
cout << "Game is a Scratch.\n";
return true;
}// end else if

else

return false;






}while (1 == 1);

} //end Human vs Human Players

header:
#ifndef ttt_h
#define ttt_h

//the TicTacToe class declaration

class TicTacToe
{
public:

TicTacToe(); //default constructor

void InitializeBoard(); //initialize the board to blank spaces

void PrintBoard(); //print the current state of the Tic-Tac-Toe board

bool OccupySquare(size_t x, size_t y, char value); //occupy the square on the board

char CheckForWinner(); //checks to see if game is scratch

static const size_t rows_=3; //number of rows
static const size_t cols_=3; //number of columns



private:

bool IsValidLocation(size_t x, size_t y); //take in two coordinates and decide if they are valid

bool IsScratch(); //decide if the game is a scratch

char board[rows_][cols_]; //two-dimensional character array

};
#endif

I am unfamiliar with this.

enum CheckForWinner { WIN };
char TicTacToe::CheckForWinner() {...}

Is this even possible!? Do you mean.

enum CheckForWinner { WIN, LOSE };
char CheckWinner(CheckForWinner result) {...}

I'd focus on what you've written, before you force a cumbersome program upon us.
Topic archived. No new replies allowed.