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...
#include <iostream>
#include <cstdlib>
usingnamespace 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);
}
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]=' ';
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.