50 errors in 79 lines??

Hello all,

After my Tic-Tac-Toe game I wanted to make 4 in a row. I would need a much larger board, so I used a multidimensional array. But now I get a bunch of errors when I try to declare them...

Help please!

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
#include <iostream>
#include <cstdlib>

using namespace std;

char sq[6][5] ;

char playersymb = 'O';

char vote = 1;
int player = 1;
int b = 1;


int main ()
{
for (int i=0;i<6;i++)for (int j=0;j<5;j++)sq[i][j]=' ';

    cout<<"###########################";
    cout<<"\n# Welkom bij 4 op een rij XAN v0.9 #\n";
    cout<<"###########################\n\n";

    do
    {

    cout<<"|"<<sq[1][5]<<"|"<<sq[2][5]<<"|"<<sq[3][5]<<"|"<<[4][5]<<"|"<<[5][5]<<"|"<<[6][5]<<"|";
    cout<<"\n|-+-+-+-+-|\n";
    cout<<"|"<<sq[1][4]<<"|"<<sq[2][4]<<"|"<<sq[3][4]<<"|"<<[4][4]<<"|"<<[5][4]<<"|"<<[6][4]<<"|";
    cout<<"\n|-+-+-+-+-|\n";
    cout<<"|"<<sq[1][3]<<"|"<<sq[2][3]<<"|"<<sq[3][3]<<"|"<<[4][3]<<"|"<<[5][3]<<"|"<<[6][3]<<"|";
    cout<<"\n|-+-+-+-+-|\n";
    cout<<"|"<<sq[1][2]<<"|"<<sq[2][2]<<"|"<<sq[3][2]<<"|"<<[4][2]<<"|"<<[5][2]<<"|"<<[6][2]<<"|";
    cout<<"\n|-+-+-+-+-|\n";
    cout<<"|"<<sq[1][1]<<"|"<<sq[2][1]<<"|"<<sq[3][1]<<"|"<<[4][1]<<"|"<<[5][1]<<"|"<<[6][1]<<"|";
    cout<<"\n|---------|\n";


    if (player == 1)
    {
    playersymb = 'X';
    cout<<"\n\nHet is de beurt aan speler "<<player<<".\n";
    player++;
    }

    else
    {
        playersymb = 'O';
        cout<<"\n\nHet is de beurt aan speler "<<player<<".\n";
        player--;
    }
    }while(true);

}
Last edited on
Your array indices are wrong. The indices are meant to go from 0 to size-1, not from 1 to size. Classic mistake :D
Array indexes start at 0, not 1.
Does it matter that I don't assign a char to them?
I still get the error:
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\oef\4 op een rij .cpp|8|error: expected constructor, destructor, or type conversion before '=' token|

You can't have code like sq[1][1] = ' '; outside a function. And you really need to read about loops.
All these lines can be reduced to
for (int i=0;i<6;i++)for (int j=0;j<5;j++)sq[i][j]=' ';
Still I have this errors:

|58|error: expected primary-expression before '[' token|
The code in your do{} is quite messed up. Firstly, you put [4][5] whereas you meant sq[4][5] and there more bits like that. Secondly, your array indices are still invalid like i mentioned before sq[3][5] not a valid index, i think you want sq[2][4]. You should check your code rigorously for errors like that.
Last edited on
Thanks all, it works now.
nvm, topic solved!
Last edited on
Topic archived. No new replies allowed.