How to Cout a WHOLE array?
Mar 30, 2012 at 3:25am UTC
Hi!
I'm creating a game where a user is able to move. I'm powering movement using a multi-dimensional array ( [15][78] )
My question to the community, is how would I go about couting the contents of every entry of the array?
Below is a sample of a for loop that is designed to set the 1st entry of all lines to the hash key, and cout it.
1 2 3 4 5 6 7
for (int i=0;i<=15;i++;) {
map[i][1] = '#' ;
cout << map[i][1];
i++;
}
How would I set the first entry and last entry of each line to the hash, and then cout the whole array?
Mar 30, 2012 at 3:39am UTC
Have a pair of nested for loops to iterate over each index of the array.
Mar 30, 2012 at 3:41am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
using namespace std;
int main()
{
int rows, columns;
char numbers[15][78];
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < columns; col++)
cout << numbers[row][col] << " " ;
}
}
Is this what you were looking for?
EDIT: changed numbers[15][78] to a char.
Last edited on Mar 30, 2012 at 3:42am UTC
Mar 30, 2012 at 3:45am UTC
@paulthepenguin: Don't just give solutions out like that. Better if TC actually has to think.
Mar 30, 2012 at 8:59pm UTC
I wasn't sure how to explain it, and didn't want to leave him all by himself. Next time I will think of a way to explain it without giving out the answer.
Topic archived. No new replies allowed.