Help writing a Battleship board game program

Ok, so I went to my professor and got some help. Now my program is a bit more organized, but I cant get the ships to print onto the grid that I created. Should I use a FOR loop to print it onto the grid? and what should I do about variables? I use X and Y a LOT now, and I wonder if that is the reason I am having trouble printing to the screen. What I need to happen is for 2 horizontal and 2 vertical ships to be randomly placed randomly in the 10x10 grid. I have to use the RAND function to place them, and I have to be able to label each coordinate as SHIP, HIT, MISS, or FREE. For now, all I need to be able to do is place the ships on the grid and print them out on the grid. To do that, the program needs to declare the state of each coordinate as SHIP, HIT, MISS, or FREE and print out an appropriate character to represent that. As it is, it wont print anything other than the grid. [note that at this point in the assignment, I only need to worry about FREE or SHIP]. Can any of you give me some advice on how to correctly print the ships? Here is 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
 #include <iostream>
using namespace std;
int main()
{

	
	int i;//y grid 0-9
	int k;//y grid "-----"
	int row;
	int x;
	int y;
	int board [10][10];
	int column;
	enum state {FREE, SHIP, MISS, HIT} ;	

	

//-------------Random Ship Grid Assignments and Overlap Checks---------//

//Vertical Ships
	//Vertical Ship 1
	x = rand () % 8;
	y = rand () % 8;
	if(x == SHIP)
		{
		x= rand () % 8;
		} else
	if(y == SHIP)
		{
		y= rand () % 8;
		}
	board [x][y] = SHIP;
	board [x][y+1] = SHIP;
	board [x][y+2] = SHIP;
	//Vertical Ship 2
	y = rand () % 8;
	y = rand () % 8;
	if(x == SHIP)
		{
		x= rand () % 8;
		} else
	if(y == SHIP)
		{
		y= rand () % 8;
		}
	board [x][y] = SHIP;
	board [x][y+1] = SHIP;
	board [x][y+2] = SHIP;
//horizontal ships
        //Horizontal Ship 1
	x = rand () % 8;
	y = rand () % 8;
	if(x == SHIP)
		{
		x= rand () % 8;
		} else
	if(y == SHIP)
		{
		y= rand () % 8;
		}	
	board [x][y] = SHIP;
	board [x+1][y] = SHIP;
	board [x+2][y] = SHIP;
	//Horizontal Ship 2
	x = rand () % 8;
	y = rand () % 8;
	if(x == SHIP)
		{
		x= rand () % 8;
		} else
	if(y == SHIP)
		{
		y= rand () % 8;
		}	
	board [x][y] = SHIP;
	board [x+1][y] = SHIP;
	board [x+2][y] = SHIP;
//===============================================================//	

/*----------------------Map/Grid---------------------------------*/ 

	for(x=0;x<10;x++)
		{	
		for(y=0;y<10;y++)
			{
			board [x][y] = FREE;
			}
		}
	cout << "  ";
	for (i=0;i<10;i++)
		{
		
		cout << " " << i ;//y grid 0-9
		}
	cout << endl;
	cout << "  ";
	for (k=0;k<20;k++)
		{
		cout << "-";//y grid "------"
		}
	cout << endl;
	for (row=0; row<10; row++) 
		{	
		
		for (column=1;column<10;column++)
			{
			cout << column << "|" << endl;
			}

		for (column=1; column<10; column++)
			{
			 if(board [x][y] == FREE)
				{
				cout << "  ";
				} else 
			if(board [x][y] == SHIP)
				{
				cout << "++";
				} else
			if(board [x][y] == HIT)
				{
				cout << "**";
				} else
			if(board [x][y] == MISS)
				{
				cout <<"..";
				}
			}
		for(row=1; row <10; row++)	
			{
			if(board [x][y] == FREE)
				{
				cout << "  ";
				} else 
			if(board [x][y] == SHIP)
				{
				cout << "++";
				} else
			if(board [x][y] == HIT)
				{
				cout << "**";
				} else
			if(board [x][y] == MISS)
				{
				cout <<"..";
				} 
				cout << endl;
				}
			}
			cout << endl;
     	
//=========================================================//


  return 0;
}

Topic archived. No new replies allowed.