|
From: Jason H. <jas...@bt...> - 2002-03-25 03:35:31
|
The errors you are getting are all due to simple typing errors. If you =
look in the enum you have substituted the number 0 with the letter O, =
notice the subtle difference in width between letter and number. So =
where you have previously put zero you need to put the letter O, but =
only for the lines dealing with the enumeration, and returning an =
enumeration type. Another mistype you have is where a ) bracket has been =
substituted for a } brace.
If you go through the errors double clicking the top one and correct the =
error, and then recompiling eventualy you will get a full compile. =
However I suggest you look at the code as the game doesn't apear to work =
properly, so there may be other more subtle erros, maybe mistyped =
numbers etc...
Jason.
----- Original Message -----=20
From: Danny Austin=20
To: dev...@li...=20
Sent: Monday, March 25, 2002 12:55 AM
Subject: [Dev-C++] errors
HEY GUYS,
I'm that newbie guy that keeps having trouble. I got a book "C++ for =
the absolute beginner," well this beginner doesn't still get it. So I'm =
wondering if you can explain what the book is failing to explain. Below =
is a program I typed in, that is giving me fits over "enum" and all its =
"returns" I feel like I missing something in my lib.'s but I'm not sure. =
I have double checked everything several times to the book and from all =
that I can see I have typed it out just as the book has it. I take it =
though one complier will do things differently than another and I know =
the author is using a different complier. So if anyone can help me I'm =
all ears. =20
THANKS DANNY!!
//6.5 - Tic Tac Toe
#include <iostream>
#include <string>
using namespace std;
enum SquareState { blank =3D ' ' , X =3D 'X', 0=3D '0' };
class gameBoard
{
private:
const int WIDTH;
const int HEIGHT;
int* GameBoard;
public:
gameBoard() : WIDTH(3), HEIGHT(3)
{
GameBoard =3D new int[9];
for (int i =3D 0; i < 9; i++)
*(GameBoard + i) =3D blank;
}
~gameBoard() {delete[] GameBoard;}
void setX(int h, int w);
void set0(int h, int w);
bool isTaken(int h, int w);
SquareState isLine();
void draw();
};
void gameBoard::setX(int h, int w)
{
*(GameBoard + h*HEIGHT + w) =3D X;
}
void gameBoard::set0(int h, int w)
{
*(GameBoard + h*HEIGHT + w) =3D 0;
}
bool gameBoard::isTaken (int h, int w)
{
return *(GameBoard + h*HEIGHT + w) !=3D ' ';
}
SquareState gameBoard::isLine()
{
if(*GameBoard=3D=3DX && *(GameBoard +1)=3D=3DX && *(GameBoard =
+2)=3D=3DX)
return X;
if(*GameBoard=3D=3D0 && *(GameBoard +1)=3D=3D0 && *(GameBoard =
+2)=3D=3D0)
return 0;
if(*(GameBoard +3)=3D=3DX && *(GameBoard +4)=3D=3DX && =
*(GameBoard +5)=3D=3DX)
return X;
if(*(GameBoard +3)=3D=3D0 && *(GameBoard +4)=3D=3D0 && =
*(GameBoard +5)=3D=3D0)
return 0;
if(*(GameBoard +6)=3D=3DX && *(GameBoard +7)=3D=3DX && =
*(GameBoard +8)=3D=3DX)
return X;
if(*(GameBoard +6)=3D=3D0 && *(GameBoard +7)=3D=3D0 && =
*(GameBoard +8)=3D=3D0)
return 0;
=20
if(*GameBoard=3D=3DX && *(GameBoard +3)=3D=3DX && *(GameBoard =
+6)=3D=3DX)
return X;
if(*GameBoard=3D=3D0 && *(GameBoard +3)=3D=3D0 && *(GameBoard =
+6)=3D=3D0)
return 0;
if(*(GameBoard +1)=3D=3DX && *(GameBoard +4)=3D=3DX && =
*(GameBoard +7)=3D=3DX)
return X;
if(*(GameBoard +1)=3D=3D0 && *(GameBoard +4)=3D=3D0 && =
*(GameBoard +7)=3D=3D0)
return 0;
if(*(GameBoard +2)=3D=3DX && *(GameBoard +5)=3D=3DX && =
*(GameBoard +8)=3D=3DX)
return X;
if(*(GameBoard +2)=3D=3D0 && *(GameBoard +5)=3D=3D0 && =
*(GameBoard +8)=3D=3D0)
return 0;
=20
if(*GameBoard=3D=3DX && *(GameBoard +4)=3D=3DX && *(GameBoard =
+8)=3D=3DX)
return X;
if(*GameBoard=3D=3D0 && *(GameBoard +4)=3D=3D0 && *(GameBoard =
+8)=3D=3D0)
return 0;
if(*(GameBoard +2)=3D=3DX && *(GameBoard +4)=3D=3DX && =
*(GameBoard +6)=3D=3DX)
return X;
if(*(GameBoard +2)=3D=3D0 && *(GameBoard +4)=3D=3D0 && =
*(GameBoard +6)=3D=3D0)
return 0;
return blank;
=20
}
void gameBoard::draw()
{
cout << endl;
for(int i=3D0; i < HEIGHT; i++)
{
cout << (char)*(GameBoard + i*HEIGHT);
for(int c=3D1; c < WIDTH; c++)
cout << " | " << (char)*(GameBoard + i*WIDTH + =
c);
cout << endl << "-------" << endl;
}
}
class Game
{
public:
gameBoard* doInput(string player, gameBoard* gb);
bool inRange(int test);
};
gameBoard* Game::doInput(string player, gameBoard* gb)
{
gb->draw();
=20
string letter;
if (player.compare("one") =3D=3D 0)
letter =3D "X";
else if (player.compare("two") =3D=3D 0)
letter =3D "0";
else return gb;
=20
int input1, input2;
=20
do {
=20
do {
cout << "\nPlayer " << player.c_str()
<< ", please enter a row number to put an "
<< letter.c_str() << ": ";
cin >> input1;
}while(!inRange(input1));
=20
do {
cout << "\nPlease enter a column number to put an "
<< letter.c_str() << ": ";
cin >> input2;
}while(!inRange(input2));
=20
}while (gb->isTaken(input1,input2));
=20
if (player.compare("one") =3D=3D 0)
gb->setX(input1, input2);
else gb->set0(input1, input2);
=20
return gb;
=20
}
bool Game::inRange(int test)
{
return test > -1 && test < 3;
)
int main( void )
{
gameBoard* gb =3D new gameBoard;
Game g;
string player1, player2;
cout << "Welcome to Tic Tac Toe!"
<< "\nPlayer one, please enter your name: ";
cin >> player1;
cout << "\nPlayer two, please enter your name: ";
cin >> player2;
=20
while (gb->isLine() =3D=3D ' ')
{
gb =3D g.doInput("one",gb);
gb =3D g.doInput("two",gb);
}
gb->draw();
if(gb->isLine() =3D=3D X)
cout << "\nPlayer one, you win!"
<< "\nGame Over.";
else cout << "\nPlayer two, you win!"
<< "\nGame Over.";
return 0;
}
|