Classes and 2D arrays

SO i have to make a 2D array of type Organism for my class, this is my code, we are using C++ and visual studio, this code "succeeds" but doesn't actually print anything, and help or suggestions would be great.

///////HEADER

#include <iostream>
#include <string>
using namespace std;

class Organism
{
friend void SetAlive();
friend char ShowSquare(int, int);
friend void CheckSquare(int, int);
friend void DisplaySquare();

private:
int alive;
public:
Organism(){}
Organism(int);

};

Organism::Organism(int a)
{
alive = a;
}

//////////////CPP FILE

#include "NewOrg.h"
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;


const int ROWS = 20;
const int COL = 20;
Organism grid[ROWS][COL];

int main()
{
SetAlive();
DisplaySquare();

return 0;
}
// END MAIN
// FUNCTION DECLARATIONS
void DisplaySquare()
{

for(int i = 0;i > ROWS;i++){

for(int j = 0; j > COL; j++){
cout << ShowSquare(i,j);

}
cout << endl;
}
}
char ShowSquare(int a, int b)
{

if (grid[a][b].alive == 1)
{
return '0';
}

else{return '-';}

}
void SetAlive()
{
grid[1][1].alive = 1;
grid[2][2].alive = 1;
grid[3][3].alive = 1;
grid[3][1].alive = 1;
grid[4][1].alive = 1;
grid[6][4].alive = 1;
return;
}
void CheckSquare(int a,int b)
{


return;
}
Just a few notes... Please use the code tags for easier viewing by your peers. to do so select your code and then click the button next to or bellow your post that has two brackets like this
<>..it makes things so much easier to read.

That being said. what is this 'friend' identifier, I've never seen it
@Seraphimsan

A friend function is used for accessing the non-public members of a class. A class can allow non-member functions and other classes to access its own private data, by making them friends. Thus, a friend function is an ordinary function or a member of another class.


@kenshin

can you please put ur codes in tags please
loop condition is wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
void DisplaySquare()
{

for( int i = 0;i < ROWS;i++)
	{
		for( int j = 0; j < COL; j++)
		{
			cout << ShowSquare(i,j);

		}
		cout << endl;
	}
}
i feel kind of dumb for not seeing that, so now it works.
Thank you for clearing that Up...i've been programming in c++ for 4 years...I'm very surprised that has never come up in my learning :O
Topic archived. No new replies allowed.