FOR loop to populate a 2D array
Hi,
I am trying to populate a two dimensional array using a FOR loop.
This is what I have made so far:-
Code:
#include <iostream>
using namespace std;
int main()
{
int array2d[2][2];
int i = 0;
int j = 0;
for(i=0, j=0;i<4, j<4;i++, j++)
{
cout << "Outer loop " << endl;
cout << "Enter the number for array location " << i << j << endl;
for(j=0;j<4;j++)
{
cout << "Inner loop " << endl;
cout << "Enter a number for array location " << i << j << endl;
cin >> array2d[i][j];
}
}
cout << array2d[0][0] << endl;
cout << array2d[0][1] << endl;
cout << array2d[1][0] << endl;
cout << array2d[1][1] << endl;
system("pause");
}
I have two problems.
The first is that when the contents of the array are 'cout'd', 2 'containers' seem to still hold the old 'nonsense' values.
The second is that I am wanting to ask the user:-
Quote:
cout << "Enter the number for array location " << i << j;
so that it says 0,0 then 0,1 then 1,0 then 1,1 but am a little confused on how to go about that. I have found that he other FOR loop is only iterated once when the program runs.
The first problem is my main concern though, as I thought I had constructed the FOR loops correctly.
Many thanks!