Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tic Tac Toe Game

10 views
Skip to first unread message

Booter

unread,
Mar 24, 2009, 6:15:21 PM3/24/09
to
Hello,

I have a tic tac toe game that I have just coded but I cannot get it
to complie. In Visual Studio 2008 I keep getting the error : error
C2065: 'checkForWin' : undeclared identifier

My code is below. If anyone can help out that would be awesome.


#include <iostream>

using namespace std;

char board[10]={'1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9'};
int i;
int x;

class gameBoard
{
public:

void drawBoard() // draws the game board
{
for (x = 0; x < 2; x++)
{
cout << board[x];
cout << " | ";
}

cout << board[2];
cout << endl;
cout << "----------" << endl;

for (x = 3; x < 5; x++)
{
cout << board[x];
cout << " | ";
}

cout << board[5];
cout << endl;
cout << "----------" << endl;

for (x = 6; x < 8; x++)
{
cout << board[x];
cout << " | ";
}

cout << board[8];
cout << endl;
}

bool checkForWin() //This function checks for wins in the game
{
if (board[0] == board[1] && board[0] == board[2]) //
Checks top row
return true;
else if (board[0] == board[4] && board[0] == board
[8]) // Checks
diagnal from top left to bottom right
return true;
else if (board[0] == board[3] && board[0] == board
[6]) // Checks
first column
return true;
else if (board[3] == board[4] && board[3] == board
[5]) // Checks
middle row
return true;
else if (board[6] == board[7] && board[6] == board
[8]) // Checks
last row
return true;
else if (board[2] == board[4] && board[2] == board
[6]) // Checks
diagonal from top right to bottom left
return true;
else if (board[4] == board[1] && board[4] == board
[7]) // Checks
second column
return true;
else if (board[2] == board[5] && board[2] == board
[8]) // Checks
last column
return true;
else
return false;
}

};

int main()
{
gameBoard myGame;
i = 1;

do
{

myGame.checkForWin();
myGame.drawBoard();

if (i == 1 || i == 3 || i == 5 || i == 7 || i == 9)
{
cout << "You are X. Pick a number: ";
cin >> x;
board[x]= 'X';
i++;
}
else if (i == 2 || i == 4 || i == 6 || i == 8)
{
cout << "You are O. Pick a number: ";
cin >> x;
board[x]= 'O';
i++;
}
else
cout << endl;
}

while (checkForWin == false);
return 0;
}

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Scott Newton

unread,
Mar 25, 2009, 5:27:05 AM3/25/09
to
> while (checkForWin == false);
while (myGame.checkForWin() == false);

--
Regards
Scott Newton

Grant

unread,
Mar 25, 2009, 5:26:45 AM3/25/09
to
{ Please note that top-posting is discouraged in this group. -mod }


Your compiler is right. Perhaps you meant

while (myGame.checkForWin() == false);

--

On Mar 24, 6:15 pm, Booter <colo.av...@gmail.com> wrote:
> Hello,
>
> I have a tic tac toe game that I have just coded but I cannot get it
> to complie. In Visual Studio 2008 I keep getting the error : error
> C2065: 'checkForWin' : undeclared identifier
>
> My code is below. If anyone can help out that would be awesome.
>

[snip]

Malinka

unread,
Mar 25, 2009, 5:38:25 AM3/25/09
to
On Mar 24, 6:15 pm, Booter <colo.av...@gmail.com> wrote:
> Hello,
>
> I have a tic tac toe game that I have just coded but I cannot get it
> to complie. In Visual Studio 2008 I keep getting the error : error
> C2065: 'checkForWin' : undeclared identifier
>
> My code is below. If anyone can help out that would be awesome.
>
> int main()
> {
> gameBoard myGame;
> i = 1;
>
> do
> {
>

- myGame.checkForWin();


> myGame.drawBoard();
>
> if (i == 1 || i == 3 || i == 5 || i == 7 || i == 9)
> {
> cout << "You are X. Pick a number: ";
> cin >> x;
> board[x]= 'X';
> i++;
> }
> else if (i == 2 || i == 4 || i == 6 || i == 8)
> {
> cout << "You are O. Pick a number: ";
> cin >> x;
> board[x]= 'O';
> i++;
> }
> else
> cout << endl;
> }
>

- while (checkForWin == false);
+ while (myGame.checkForWin() == false);

> return 0;
>
> }


{ clc++m banner removed. You should not generally quote it,
since you're not responding particularly to that part.
Please take care to quote only the necessary part for context. -mod }

SG

unread,
Mar 25, 2009, 2:36:04 PM3/25/09
to
On 24 Mrz., 23:15, Booter <colo.av...@gmail.com> wrote:
> I have a tic tac toe game that I have just coded but I cannot get it
> to complie. In Visual Studio 2008 I keep getting the error : error
> C2065: 'checkForWin' : undeclared identifier

I just wanted to point out that thread also exists in
alt.comp.lang.learn.c-c++

Cheers!
SG

ldyuj...@yahoo.com.cn

unread,
Mar 25, 2009, 2:33:32 PM3/25/09
to
not
while (checkForWin == false);

should be:
while (myGame.checkForWin() == false);

Vladimir Ivanov

unread,
Mar 25, 2009, 2:33:20 PM3/25/09
to
On 25 мар, 00:15, Booter <colo.av...@gmail.com> wrote:
> Hello,
>
> I have a tic tac toe game that I have just coded but I cannot get it
> to complie. In Visual Studio 2008 I keep getting the error : error
> C2065: 'checkForWin' : undeclared identifier
>
> ...

>
> while (checkForWin == false);
> return 0;
>
> }

{ edits: quoted banner removed. don't quote extraneous material. tia. -mod }

At the end: "while (checkForWin == false);"
It seems to me, shout be "while (myGame.checkForWin() == false);"

0 new messages