2D array table
Hello, I am trying yo build the following 2D array table:::
0 1 2 3 4 5 6 7
0|0 0 0 0 9 0 0 0
1|0 0 0 0 0 0 0 0
2|9 0 9 0 0 0 9 0
3|0 0 0 0 0 0 0 0
4|0 9 0 9 0 0 0 0
5|0 9 0 0 9 0 9 0
6|0 0 0 0 0 0 0 0
7|0 0 0 0 0 0 9 0
|
Instead of the previous output I get the following output:::
0 1 2 3 4 5 6 7
- - - - - - - -
0|0 0 0 0 9 0 0 0
1|0 0 0 0 0 0 0 0
2|9 0 9 0 0 0 9 0
3|0 9 0 9 0 0 0 0 // from that rows 3 -4 -5 -4 - 6 - 7
4|9 0 9 0 0 0 9 0 // are wrong
5|0 0 0 0 0 0 0 0 // I am stuck and I need help
6|0 9 0 9 0 0 0 0
7|9 0 9 0 0 0 9 0
|
below it's my code:::
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
|
int main(){
int counter =0;
int board[8][8];
cout<<""<<endl;
cout<<" 0 1 2 3 4 5 6 7 "<<endl;
cout<<" - - - - - - - - "<<endl;
for(int x=0;x<7;x++){
if(x==0)
cout<<counter++<<"|0 0 0 0 9 0 0 0"<<endl;
if (x==1 || x ==6 || x == 3)
cout<<counter++<<"|9 0 9 0 0 0 9 0";
else
if (x==5 || x==2 || x== 7 )
cout<<counter++<<"|0 9 0 9 0 0 0 0";
else
for(int y=0;y<7;y++){
if(y==1 )
cout<<counter++<<"|0 0 0 0 0 0 0 0";
if(board[x][y] == 0 )
cout<<setw(1);
}
cout <<endl;
}
return 0;
}
| |
Last edited on
Topic archived. No new replies allowed.