Labels in Arrays

So currently I have figured out reading from a .txt file into an array but I need to somehow mix strings into the equation. My function need to do this:

Month                    Rec             Tent           RV           Back       T Overnight
                      Visitors          Campers       Campers       country      Stays
January                   6340	             27	           34	          6	   67
Feburary                 12191	              7	            7	          2        16
March                    11548	             14	           24	         10	   47
April                    36053	            323	          231	         27	  581
May                      74361	           2764	         1890	       1101	 5755
June                    256462	           4879	         1363	       2727	 8970
July                    483291	          13797	         8823	       7038	29658
August                  358885	          13100	        10346	       7816      3162
September               141297	           8945	        10492	       2290     21728
October                 119175	           3193	         6164	        281      9638
November                 22377	            337	          629	         22       988
December                 13653	             24	           20	          7        51


and currently it only does this:
   
      6340         27         34          6         67
     12191          7          7          2         16
     11548         14         24         10         47
     36053        323        231         27        581
     74361       2764       1890       1101       5755
    256462       4879       1363       2727       8970
    483291      13797       8823       7038      29658
    358885      13100      10346       7816       3162
    141297       8945      10492       2290      21728
    119175       3193       6164        281       9638
     22377        337        629         22        988
     13653         24         20          7         51


here is the code I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
int main()
{
	
// creating the display file

// creating the arrays ROWS ARE ALWAYS FIRST "[]"[] 
	const int month_column = 5;
	const int month_row = 12;   // array element size 60 (12 rows x 6 columns)
	int ppl[month_row][month_column];//january array - has 5 elements 
	int countc = 0;
	int countr = 0;
	int count = 0;
	int x;
	
	
	ifstream Months;
	ifstream Visitors;
	

	
	Months.open("Months.txt");
	Visitors.open("Visitors.txt");
	
	
	
	for (int row = 0; row < month_row; row++)
	{
		for (int col = 0; col < month_column; col++)
		{
			Visitors >> ppl[row][col];
		}
	}
	
	for (int row = 0; row < month_row; row++)
	{
		for (int col = 0; col < month_column; col++)
		{
			cout << right << setw(10) << ppl[row][col] << " ";
		}
		cout << endl;
	}
        Visitors.close();
        system("pause");
}


Months.txt is this:
January February March April May June July August September October November December

and Visitors.txt contains the output my code does.
Last edited on
You may add three fixed size arrays:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const char *header1[] = { "Rec", "Tent", "RV", ... };
const char *header2[] = { "Visitors", "Campers", "Campers", ... };
const char *month[] = { "January", "February", "March", ... };

cout << "Month";

... // loop for header1
... // loop for header2

...

	for (int row = 0; row < month_row; row++)
	{
		for (int col = 0; col < month_column; col++)
		{
			cout << month[row] << right << setw(10) << ppl[row][col] << " ";
		}
		cout << endl;
	}
Topic archived. No new replies allowed.