multi dimension array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
7-20 Multi-Dimensional Array

Do an advanced, multi-dimensional-array Array. 
*/
#include <iostream>
#include <string>
using namespace std;
void main()
{string table[3][3];
string word;
cout << "Enter words and I will put them into a 3 by 3 table for you.\n";
cout << "What 3 words do you want to go into the rows: \n";
cin >> word;
for (int n=1; n < 3; n++)
{table[n][j]=word;}
cout << "What 3 words do you want to go into the columns: \n";
cin >> word;
for (int j=1; j < 3; j++)
{table[n][j]=word;}

system("pause")

}


Heyy guys, this is my code, and i was wondering if i am on the right track towards this multi dimensional array? and, at the end, how would i output all the info as a table?
You need your 2 for loops, to go from 0 to 2, to get the 3 inputs. for(int n=0;n<3;n++).(Same for j loop). ''n' and later 'j', then would equal 0, 1 and 2, through the loops.
you can use setw().
@whitenite1 would that mean the for loop for my int j needs to be inside the one for int n?
@magadavixt

Yes. One goes right after the other.
1
2
3
4
5
6
7
for (int n=0; n < 3; n++)
for(int j=0;j<3;j++)
{
cout << "What 3 words do you want to go into the columns: \n";
cin >> word;
table[n][j]=word;
}

The fist time through, n is equal to 0, so you are inputting a word to table[0][0], table[0][1] then table[0][2]. Then, n equals 1, then you're inputting to table[1][0], table[1][1] then table[0][2]. Same for n equaling 3. If your wanting the inputted word to go to table[0][0], table[1][0] then table[2][0], instead, then you would change table[n][j]=word; to table[j][n]=word;

Get rid of the other two for loops. They will cause problems for you.

Hope this helps.
Topic archived. No new replies allowed.