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! ]
--
Regards
Scott Newton
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]
- 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 }
I just wanted to point out that thread also exists in
alt.comp.lang.learn.c-c++
Cheers!
SG
should be:
while (myGame.checkForWin() == false);
{ 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);"