XO - Please Read this and Reply.

Jul 28, 2008 at 11:23am
A couple of days a go i was stuck with my X & O Game or as i call it Tic Tac Toe xD

Well anyway i got a bit confused and remade the input function.

But i dont think bits of it are correct can you help point some stuff out?...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void Input(){
    int x, y;
	bool done = false;
	while(done == false)
		cout << "Player 1 please enter the x coordinate...";
		cin >> x;
		cout << "Player 1 please enter the y coordinate...";
		cin >> y;
			if ( x < 1 || x  > 3 || y < 1 || y > 3 )
				done = true;
			else
				if (! XOBoard[x % 3 + y / 3]=' ')
					XOBoard[y][x] = 'X';
				else
					done = true;
}
Last edited on Jul 28, 2008 at 12:13pm
Jul 28, 2008 at 11:33am
Please Read this and Reply.

It's good that you pointed that out. Otherwise, regarding the fact that the subject line contains absolutely no useful information at all, thus making it impossible for me to determine whether or not I am interested or capable of answering your question, I would have thought that you simply posted to be ignored.

So, rest assured: I read and replied. Hope that helps.
Jul 28, 2008 at 12:14pm
WoW dude your not a fucking ass.....
Jul 28, 2008 at 12:20pm
at line 12:

! XOBoard[x % 3 + y / 3]=' '

should be
! (XOBoard[x % 3 + y / 3]!=' ' )
or
! (XOBoard[x % 3 + y / 3]==' ' )

Right?
Jul 28, 2008 at 12:27pm
oh thanks i dunno what that bit does my teach told me to stick it in it checks the space to see if theres a X or an O there if not its ok and the player can put there X or O there i think.
Jul 28, 2008 at 2:05pm
I dunno what u mean.
Sorry,I just tell u make a mistake.
Jul 28, 2008 at 3:28pm
The obvious ommision is the {} pair arround the body of the while loop - this may be a typo, but if not it would explain why you are having problems.
The logic of setting done = True also looks wrong.
I guess you want to loop until the user inputs a valid co-ordinate pair, so have modified teh logic to matxh this.
You have not shown the definition of XOBoard, but it look odd to reference it as 1D and 2D in consecutive lines, so modified to a consistent 2D style.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void Input()
{
    int x, y;
    bool done = false;
    while(done == false)
    {              
	cout << "Player 1 please enter the x coordinate...";
	cin >> x;
	cout << "Player 1 please enter the y coordinate...";
	cin >> y;
	if ( x >= 1 && x  <=3  && y >= 1 && y <= 3 )
        {
	   if (XOBoard[y][x]=' ')
          {
	      XOBoard[y][x] = 'X';
  	      done = true;
          }
       }
    }
}
Topic archived. No new replies allowed.