Have errors on Connect-4 game

Connect-4 have 5 errors:
#include <iostream>
using namespace std;


//The workings of Connect Four
class connectFour{
int player;
int score[2];
int board[6][7]; //6 = Rows, 7 = Columns
int move;
bool win;

public:
//Set the player number to one and the scores to zero
connectFour(){
player = 1;
score[0] = 0;
score[1] = 0;
win = false;

//Initialize board array
for (int i = 0; i < 6; i++){
for (int x = 0; x < 7; x++){
board[i][x] = 0;
}
}
}

//Setup the turn by first checking for a win
//If there is no win, continue by displaying the board
//and getting the player's move
void startTurn(){
checkWin();
if (win == true){
clearScreen();
display();
cout<< "Player #" << player << " has won!" <<endl <<endl;
}
else{
display();
gatherMove();
}
}

//Display the board
void display(){
clearScreen();
cout<< " 1 2 3 4 5 6 7 " <<endl;
for (int i = 0; i < 6; i++){
for (int x = 0; x < 7; x++){
cout<< "[" << board[i][x] << "]";
}
cout<< endl;
}
}

//Gather the player's move
void gatherMove(){
int emptySpots = 0;
cout<< endl << "Player #" << player << ": Move to which space? ";
cin>> move;

//If the player enters anything above 7, set it to 7
if (move > 7){move = 7;}
//If the player enters anything below 0, set it to 0
if (move < 0){move = 0;}

//Determine where the player's piece falls
//If something occupies the lowest point already, put it above
for (int i = 5; i >= 0; i--){
if (board[i][move - 1] == 0){
board[i][move - 1] = player;
break;
}
else{
emptySpots += 1;
}
}

//If there are no more rows in a column, tell the player to try again
if (emptySpots == 6){
cout<< endl << "There are no empty spots on #" << move << "! Try again!";
gatherMove();
}

//Set the next player to move
if (player == 1){player = 2;}
else {player = 1;}

//Call start of next turn
startTurn();
}

//Check for any winning combinations
void checkWin(){
int start = 0;

//Horizontal Win
for (int i = 0; i < 6; i ++){
for (start = 0; start <= 3; start++){
if ((board[i][start] == board[i][start+1] && board[i][start+1] == board[i][start+2] && board[i][start+2] == board[i][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}

//Vertical Win
for (int i = 0; i < 7; i ++){
for (start = 0; start <= 2; start++){
if ((board[start][i] == board[start+1][i] && board[start+1][i] == board[start+2][i] && board[start+2][i] == board[start+3][i]) && (board[start][i] != 0)){
win = true;
player = board[start][i];
break;
}
}
}

//Diagonal Win - "/"
for (int i = 3; i < 6; i ++){
for (start = 0; start <= 3; start++){
if ((board[i][start] == board[i-1][start+1] && board[i-1][start+1] == board[i-2][start+2] && board[i-2][start+2] == board[i-3][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}

//Diagonal Win - "\"
for (int i = 0; i < 3; i ++){
for (start = 0; start <= 4; start++){
if ((board[i][start] == board[i+1][start+1] && board[i+1][start+1] == board[i+2][start+2] && board[i+2][start+2] == board[i+3][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}
}

//Clear the screen
//Set for OSX currently - Change the inner system call for Windows or Linux
void clearScreen(){
system("clear");
}

};

//Main function - Nice and small just like I like it!
int main (int argc, char * const argv[]) {
connectFour play;
play.startTurn();

return 0;
}
Do you want to use code tags and also tell us where these errors are?
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
Connect-4 have 5 errors:
#include <iostream>
using namespace std;


//The workings of Connect Four
class connectFour{
int player;
int score[2];
int board[6][7]; //6 = Rows, 7 = Columns
int move;
bool win;

public:
//Set the player number to one and the scores to zero
connectFour(){
player = 1;
score[0] = 0;
score[1] = 0;
win = false;

//Initialize board array
for (int i = 0; i < 6; i++){
for (int x = 0; x < 7; x++){
board[i][x] = 0;
}
}
}

//Setup the turn by first checking for a win
//If there is no win, continue by displaying the board
//and getting the player's move
void startTurn(){
checkWin();
if (win == true){
clearScreen();
display();
cout<< "Player #" << player << " has won!" <<endl <<endl;
}
else{
display();
gatherMove();
}
}

//Display the board
void display(){
clearScreen();
cout<< " 1 2 3 4 5 6 7 " <<endl;
for (int i = 0; i < 6; i++){
for (int x = 0; x < 7; x++){
cout<< "[" << board[i][x] << "]";
}
cout<< endl;
}
}

//Gather the player's move
void gatherMove(){
int emptySpots = 0;
cout<< endl << "Player #" << player << ": Move to which space? ";
cin>> move;

//If the player enters anything above 7, set it to 7
if (move > 7){move = 7;}
//If the player enters anything below 0, set it to 0
if (move < 0){move = 0;}

//Determine where the player's piece falls
//If something occupies the lowest point already, put it above
for (int i = 5; i >= 0; i--){
if (board[i][move - 1] == 0){
board[i][move - 1] = player;
break;
}
else{
emptySpots += 1;
}
}

//If there are no more rows in a column, tell the player to try again
if (emptySpots == 6){
cout<< endl << "There are no empty spots on #" << move << "! Try again!";
gatherMove();
}

//Set the next player to move
if (player == 1){player = 2;}
else {player = 1;}

//Call start of next turn
startTurn();
}

//Check for any winning combinations
void checkWin(){
int start = 0;

//Horizontal Win
for (int i = 0; i < 6; i ++){
for (start = 0; start <= 3; start++){
if ((board[i][start] == board[i][start+1] && board[i][start+1] == board[i][start+2] && board[i][start+2] == board[i][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}

//Vertical Win
for (int i = 0; i < 7; i ++){
for (start = 0; start <= 2; start++){
if ((board[start][i] == board[start+1][i] && board[start+1][i] == board[start+2][i] && board[start+2][i] == board[start+3][i]) && (board[start][i] != 0)){
win = true;
player = board[start][i];
break;
}
}
}

//Diagonal Win - "/"
for (int i = 3; i < 6; i ++){
for (start = 0; start <= 3; start++){
if ((board[i][start] == board[i-1][start+1] && board[i-1][start+1] == board[i-2][start+2] && board[i-2][start+2] == board[i-3][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}

//Diagonal Win - "\"
for (int i = 0; i < 3; i ++){
for (start = 0; start <= 4; start++){
if ((board[i][start] == board[i+1][start+1] && board[i+1][start+1] == board[i+2][start+2] && board[i+2][start+2] == board[i+3][start+3]) && (board[i][start] != 0)){
win = true;
player = board[i][start];
break;
}
}
}
}

//Clear the screen
//Set for OSX currently - Change the inner system call for Windows or Linux
void clearScreen(){
system("clear");
}

};

//Main function - Nice and small just like I like it!
int main (int argc, char * const argv[]) {
connectFour play;
play.startTurn();

return 0;
}



Errors are on lines 20,29,176,101, and 4.
Error on line 4? On line 29? Line 176? Do you want to check these line numbers? ;)
Last edited on
You need a semi colon after the last bracket of a class. and I don't see a closing bracket for the connect four class either. Try counting your brackets to make sure they all line up.
Last edited on
@jakesweater

After changing system("clear"); to system("CLS");, the program ran great.
Topic archived. No new replies allowed.