Array output

Alright, I'm trying to create a board so it resembles a battleship board.
1-10 across the top and A-J across the left side. Currently, I'm getting
1 2 3 4 5 6 7 8 9 10
A ~ B ~ C ~ etc...

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
  #include <iostream>
  #include <string>
  #include <fstream>

    using namespace std;

int main() {

	char array[10] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' };
	char board[10][10];

	//fill array
	for (int i = 0; i < 10; i++) {
		for (int x = 0; x < 10; x++) {
			board[i][x] = '~';
		}
	}

	//output
	cout << "1 2 3 4 5 6 7 8 9 10" << endl;

		for (int row = 0; row < 10; row++) {
			for (int column = 0; column < 10; column++) {
				cout << array[column] << " " << board[row][column] << " ";
			}
			cout << endl;
		}
	


	system("pause");
	return 0;

    }
Last edited on
Your output loops need some tweaking:
19
20
21
22
23
24
25
26
27
28
29
//output
	cout << "  1 2 3 4 5 6 7 8 9 10" << endl;
    for (int row = 0; row < 10; row++) 
	{   cout << array[row] << " ";
		for (int column = 0; column < 10; column++) 
		{   cout << board[row][column] << " ";		
		}
		cout << endl;
    }
  1 2 3 4 5 6 7 8 9 10
A ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
B ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
C ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
D ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
E ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
F ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
G ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
H ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
I ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
J ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Last edited on
Thank you good sir.
Topic archived. No new replies allowed.