Trying to display the contents of an array.

How can I display the contents of an array?

What I am trying to do is populate an array and then ouptut the contents. I tried this code and it doesn't work...

I tried to use this to populate the array:
1
2
3
4
5
6
7
for (i=0; i<k; i++) 
{
     cout << "Enter a number: ";
     cin >> numbers[k];
}



and then use this to display the contents of the array:
1
2
3
for (j=0; j<k; j++)
{
     cout << numbers[k] << ", ";


When I use that what I get is the last number I entered into the array instead of each number I entered. Does anyone know what I am doing wrong?
Thanks.
1
2
3
4
5
6
7
8
9
for (int i = 0; i < k; ++i) {
 cout << "Enter a number: ";
 cin >> numbers[i];
}

for (int i = 0; i < k; ++i) {
 cout << numbers[i] << ", ";
}
Thank you very much! That did the trick. I feel a bit foolish, but thanks.
Topic archived. No new replies allowed.