best way to use if statement?

Hey, i'm pretty new to C++, i know exactly what i need to do, but i'm having trouble in figuring out how to do it =/

I making a battleship kind of game and i've got to the point where it's randomly allocating space for cities, and it displays either a 0 or a number. i want to create an if statement so the numbers display " " instead of a 0 and a "^" for a city. but i just can't figure out where to put it, here's what i have so far:

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
void NuclearWar::generateMap(int x, int y)
{
int num = 0;
int varA = 0;
int varB = 0;
m_randCities = m_cities * 2;

// generates cities in random places on map
 for(int a = 0; a < m_height; a++)
{
 for(int b = 0; b < m_width; b++)
{
 LevelGrid[a][b] = 0;
}
}
 srand(time(0));
 for(int x = 1; x <= m_randCities; x++)
{
 varA = rand() % m_height;
 varB = rand() % m_width;
 LevelGrid[varA][varB] = x;

}
}


void NuclearWar::displayMap(int m_width, int m_height, int m_cities)
{

	generateMap(x, y);

// displays map and cities
for (int row = 0; row < m_width; row++)
{

	for (int column = 0; column < m_height; column++)
  
		cout << "[" << LevelGrid[row][column] << "]";
	cout << "\n";
}

system("pause");

}


any help would be awesome, cause i'm pretty much stuck...

1
2
3
4
5
6
7
	for (int column = 0; column < m_height; column++)
                                                       //right here
//ditch this	cout << "[" << LevelGrid[row][column] << "]";
                               if (LevelGrid[row][column]) {cout<<"[^]";}
                               else {cout<<"[ ]";}
	cout << "\n";


that should work, right?
yes, that works awesomely
thank you :)
Topic archived. No new replies allowed.