need some help with an array

uiu
Last edited on
You should always use curly braces. Lines 12 and 13 are not inside the inner for loop like line 11 is.
gykjhy
Last edited on
You're still not using curly braces for the inner loop. You misunderstood what I said - I was not suggesting that you move the lines out of the loop, I was pointing out that the indentation did not match the actual truth.

Stop making guesses - think through the logic of the loops. When do you need to start a new line?
Last edited on
dthfghfd
Last edited on
So, I went back and read all the comment fully, I think this is what you meant right?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

{
	cout<<setw(2)<<"0 1 2 3 4 5 6 7"<<endl;
	cout<<"_______________"<<endl;
	
		for (row=0;row<8;row++)
		{
			for(col=0;col<8;col++)
				{
					cout<<setw(2)<<row;
					cout<<setw(2)<<col<<endl;
					cout<<setw(2)<<grid[row][col];
				}
		
		}


so they're are now all inside the inner loop, at least it looks like it
Last edited on
I have to ask...why are you outputting the column on line 11 when you already did that on line 3? With line 3, you're set for life - the rest is just printing the row and then printing the actual data on that row, for each row.
It's for a minesweeper game, so the line 3 output is acting as a coordinate header
AKA, a column header. Doesn't matter what you call it, the point is that you don't need to output col inside the loop.

Also, remember what I said - you need to be thinking about when to start a new line of output.
srdvfrs
Last edited on
You should always use curly braces. Swap lines 5 and 8.
thank you, its all displaying perfectly now :)
Topic archived. No new replies allowed.