Multi dimensional arrays

Before I get to far and realize I wasn't using the correct method. may someone tell me if this would be a good method to use where I all the user to input and high and low temps per month into a two dimensional array. I think this would work but is there another preferred way to do it that's more quicker.

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
  const int months=12;
const int high_Low=2;


//Make a function to read data. should be a two dimensional data
void getdata(unsigned int sto_highlow[][high_Low], int months, int &hightemp,int &lowtemp)

{
	//high_low can only store in two. make a variable
	

	for (int whatmonth=1;whatmonth<=months;whatmonth++)
		{
			//Reset high and low to zero everytime it gets into for loop
			
			cout<<"\nHigh Temp of ";
			switch (whatmonth)
				{
			case 1: 
				for(int high_lowtem=1;high_lowtem<=2;high_lowtem++)
				{
					cout<"High Temp of Jan: ";
					cin>>sto_highlow[whatmonth][high_lowtem];
					high_lowtem++;
					cout<<"Low Temp of Jan: ";
					cin>>sto_highlow[whatmonth][high_lowtem];
				}
That's fine to use a 2d array like that.

Suggestion:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
enum { Lows, Highs, nMeasurements };

typedef unsigned int temperatures_t[ nMeasurements ];

...

void getdata( temperatures_t ts[], ... )
{
  ...
  cin >> ts[Lows][month];
  ...
}

temperatures_t ts[ 12 ];
Topic archived. No new replies allowed.