2D array with strings and int with 'cin >>'

I am trying to write an array where the user inputs three years worth of sales data by month.

First issue, I am inputting all three years in month one as opposed to inputting
month one - year one volume, then eventually moving to year 2 volume after I go past December.

The second issue, and what I care most about, is my program is not displaying the rows in the 'cout'. Its a mess!

My code stinks, I know, I am just trying to learn about multi-dimensional arrays and thought this a good exercise, but I am struggling.

I don't expect an answer(code), but any guidance in helping me to understand where I am making my mistake would be greatly appreciated.

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
45
46
#include <iostream>
#include <string>

using namespace std;

const int rows = 12;
const int cols = 3;

int main()
{
	const char* months[rows] =
	{
	"January",
	"February",
	"March",
	"April",
	"May",
	"June",
	"July",
	"August",
	"September",
	"October",
	"November",
	"December"
	};
	int years[cols][rows] = {0};

	cout << "Enters values for each month" << endl;
	for (int month = 0; month < rows; ++month)
	{
		cout << "\n" << months[month] << "" << endl;
		cout << "---------" << endl;
		
		for (int year = 0; year < cols; ++year)
		{
		cout << "year " << year << ": ";
		cin >> years[year][month];
		}
		for (int month = 0; month < rows; ++month)
			for (int year = 0; year < cols; ++year)
			{
				cout << years[year][month] << " ";
			}
	}
		
}
Topic archived. No new replies allowed.