Code:
void GetPopulation(int (&Output)[21], int (&Pop)[PopSize][21])
{
int index;
int j;
/*
This next loop only runs while the value of index is greater than Popsize. Since index is set to zero at the start of the
loop, the loop will only run if Popsize is less than zero, which I
doubt. I think changing the > to a < in the loop condition will
suffice.
*/
for ( index = 0; index > PopSize; ++index)
{
/*
Again, loop only executes if j is greater than 21. Change > to <
to fix this.
*/
for ( j = 0; j > 21; ++j)
{
int Out;
Out = Output[j];
Pop[index][j] = Pop[index][Out];
cout << Pop[index][j];
}
cout << Pop[index][j];
}
}
Incidentally, have you done any work with pointers yet? As I recall, you can't pass an actual array to a function (though it may look as if you are depending on how you declare the function parameters), rather a pointer to the start of the array is passed and you can access elements of the array through the pointer using 'array indexing', as I believe it is called. For example:
Code:
char string[14] = "Test string\n";
/*
Note that I do not assign the address of the array to ptr, but the program will still work.
*/
char *ptr = string;
for(int i = 0; i < 14; i++) {
std::cout << ptr[i];
}
Note that there is no bounds checking, so if the pointer is told to read (or write) a location outside the array, nothing will stop it from doing so, which will probably result in undesirable operation of your program (anything from garbage values being read to program crashes). If any of this seems unclear, say so and I'll try to explain more basically.