#include <iostream>
#include <string>

using namespace std;
enum SquareState
{
(blank = 's',
X = 'X',
0 ='0')
};
class gameBoard
{
private:
const int WIDTH;
const int HEIGHT;
int* GameBoard;
public:
gameBoard(): WIDTH(3), HEIGHT(3)
{
GameBoard = new int [9];
for (int i = 0; i < 9; i++)
*(GameBoard + i) = 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)=X;
}
void gameBoard::set0(int h, int w)
{
*(GameBoard + h*HEIGHT + w)=0;
}

bool gameBoard::isTaken(int h, int w)
{
return *(GameBoard + h*HEIGHT + w)!= '';
}
SquareState gameBoard::isLine()
{
if (*GameBoard==X && *(GameBoard +1)==X && *(GameBoard +2)==X)
return X;
if (*GameBoard==0 && *(GameBoard +1)==0 && *(GameBoard +2)==0)
return 0;
if (*GameBoard +3)==X && *(GameBoard +4)==X && *(GameBoard +5)==X)
return X;
if (*GameBoard +3)==0 && *(GameBoard +4)==0 && *(GameBoard +5)==0)
return 0;
if (*GameBoard +6)==X && *(GameBoard +7)==X && *(GameBoard +8)==X)
return X;
if (*GameBoard +6)==X && *(GameBoard +7)==X && *(GameBoard +8)==X)
return 0;

if (*GameBoard==X && *(GameBoard +4)==X && *(GameBoard +8)==X)
return X;
if (*GameBoard==0 && *(GameBoard +4)==0 && *(GameBoard +8)==0)
return 0;
if (*GameBoard +2)==X && *(GameBoard +4)==X && *(GameBoard +6)==X)
return X;
if (*GameBoard +2)==0 && *(GameBoard +4)==0 && *(GameBoard +6)==0)
return 0;
return blank;
}
void gameBoard::draw()
{
cout<<endl;
for(int i=0; i < HEIGHT; i++)
{
cout << (char)*(GameBoard + i*HEIGHT);
for(int c=1; 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(std::string player, gameBoard *gb)
{
gb->draw();

string letter;
if (player.compare("one")==0)
letter= "X";
else if (player.compare("two")==0)
letter= "0";
else return gb;
int input1, input2;
do{
do{

can u tell me wats the problem

Recommended Answers

All 5 Replies

>>can u tell me wats the problem

First you need to learn how to format your program better. What you posted is absolutely terrible! Take the time to use the space-bar on your keyboard and make your program easy to read. You will probably get a better grade for it too :)

Look at the last two lines! They are just nonsense, unless of course there is more code that you did not post.

why use dynamic allocations for variable GameBoard? Its size never changes so why not just hard-code it an array of 9. Don't use dynamic allocation unless you absolutely have to such as when the size is not known until runtime or when the object is too big to put on the stack.

Otherwise, I have no idea what's wrong with your program.

then wat should i do....

then wat should i do....

fix it. its your program, not mine. I don't know what you want it to do.

First thing I suggest doing, is looking at this bit of your program carefully

enum SquareState
{
(blank = 's',
X = 'X',
0 ='0')
};

If you can't spot the errors, do some reading about enums

commented: absolutely agree with that approach. +15

How many times did you press "compile" before posting it here?

My guess is that you've tried to write the whole lot at once, pressed compile and got several hundred errors, panicked and posted the whole mess here for someone else to sort out. Or you just kept typing even though you were getting errors.

Take it in stages, like
- initialise a board
- draw a board
- place a piece
- check for winning line

Each is a relatively small step, which you either succeed at and then move onto the next step, or you post here with a specific question about the bit you're stuck on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.