my checker program

It seems like I cannot make it evaluate the way I want as if it is equals to 1, it will still show the message within while statement. Any help and advice?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
void selectPiece(int board[][8], const int COUNT, int turn, int& x, int& y)
{
	if(turn%2==0)
	{
		cout << "It is white turn." << endl;
		cout << "Please enter x: ";
		cin >> x;
		cout << "Please enter y: ";
		cin >> y;
		while(board[x-1][y-1]!=1);/*what is wrong with this while statment, it wont evaluate properly*/
		{
			cout << "Please enter x again: ";
			cin >> x;
			cout << "Please enter y again: ";
			cin >> y;
		}
	}
	else
	if(turn%2==1)
	{
		cout << "It is black turn." << endl;
		cout << "Please enter x: ";
		cin >> x;
		cout << "Please enter y: ";
		cin >> y;
		while(board[x-1][y-1]!=2);
		{
			cout << "Please enter x: ";
			cin >> x;
			cout << "Please enter y: ";
			cin >> y;
		}
	}
}
If you are curious and willing to help, here is my full program to examine(not finish):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <cstdlib>
using namespace std;

void setBoard(int [][8], const int COUNT);
void showBoard(int [][8], const int COUNT);
void movePiece(int [][8], const int COUNT, int turn);
void selectPiece(int [][8], const int COUNT, int turn, int& x, int& y);

int main()
{
	const int COUNT=8;
	int board[COUNT][COUNT];
	setBoard(board, COUNT);
	int x=1;
	while(++x)
	{
		showBoard(board, COUNT);
		movePiece(board, COUNT, x);
		//evaluate(board, COUNT);
	}
}

void setBoard(int board[][8], const int COUNT)
{
	for(int i=0; i<COUNT; ++i)
	{
		for(int j=0; j<COUNT; ++j)
		{
			if((i%2==0 && (j==0 || j==2)) || ((i%2==1) && j==1))
				board[i][j]=1;
			else
			if((i%2==1 && (j==7 || j==5)) || ((i%2==0) && j==6))
				board[i][j]=2;
			else
				board[i][j]=0;
		}
	}
}

void showBoard(int board[][8], const int COUNT)
{
	for(int i=COUNT-1; i>=0; --i)
	{
		cout << i+1 << " |";
		for(int j=0; j<COUNT; ++j)
		{
			if(board[j][i]==0)
				cout << " ";
			else
			if(board[j][i]==1)
				cout << "W";
			else
			if(board[j][i]==3)
				cout << "X";
			else
			if(board[j][i]==2)
				cout << "B";
			else
			if(board[j][i]==4)
				cout << "C";
			cout << "|";
		}
		cout << endl;
	}
	cout << "   1 2 3 4 5 6 7 8" << endl;
}

void movePiece(int board[][8], const int COUNT, int turn)
{
	int x, y;
	selectPiece(board, COUNT, turn, x, y);
	//desirePlace();
}

void selectPiece(int board[][8], const int COUNT, int turn, int& x, int& y)
{
	if(turn%2==0)
	{
		cout << "It is white turn." << endl;
		cout << "Please enter x: ";
		cin >> x;
		cout << "Please enter y: ";
		cin >> y;
		while(board[x-1][y-1]!=1);//what is wrong with this while statment, it wont evaluate properly
		{
			cout << "Please enter x again: ";
			cin >> x;
			cout << "Please enter y again: ";
			cin >> y;
		}
	}
	else
	if(turn%2==1)
	{
		cout << "It is black turn." << endl;
		cout << "Please enter x: ";
		cin >> x;
		cout << "Please enter y: ";
		cin >> y;
		while(board[x-1][y-1]!=2);
		{
			cout << "Please enter x: ";
			cin >> x;
			cout << "Please enter y: ";
			cin >> y;
		}
	}
}



8 | |B| |B| |B| |B|
7 |B| |B| |B| |B| |
6 | |B| |B| |B| |B|
5 | | | | | | | | |
4 | | | | | | | | |
3 |W| |W| |W| |W| |
2 | |W| |W| |W| |W|
1 |W| |W| |W| |W| |
   1 2 3 4 5 6 7 8
It is white turn.
Please enter x: 1
Please enter y: 1
Please enter x again: 1//<--It comes out even in correct input
Please enter y again: 1
8 | |B| |B| |B| |B|
7 |B| |B| |B| |B| |
6 | |B| |B| |B| |B|
5 | | | | | | | | |
4 | | | | | | | | |
3 |W| |W| |W| |W| |
2 | |W| |W| |W| |W|
1 |W| |W| |W| |W| |
   1 2 3 4 5 6 7 8
It is black turn.
Please enter x: 

Last edited on
while(board[x-1][y-1]!=1); <---- remove that semicolon and it works (line 85)
Thanks!
Check it like a thousand already...lol
Topic archived. No new replies allowed.