Weather array infile program

I have a file that has weather data in 3 columns and 90 rows:
6 1 C
6 2 S
6 3 R
6 4 R
6 5 C
6 6 S
6 7 S
6 8 S
6 9 S
6 10 S
6 11 C
6 12 S
6 13 C
6 14 S
6 15 S
6 16 S
6 17 C
6 18 C
6 19 R
6 20 C
6 21 S
6 22 C
6 23 S
6 24 S
6 25 S
6 26 S
6 27 S
6 28 C
6 29 S
6 30 R
7 1 R
7 2 S
7 3 S
7 4 R
7 5 R
7 6 S
7 7 C
7 8 S
7 9 S
7 10 S
7 11 S
7 12 S
7 13 R
7 14 C
7 15 C
7 16 S
7 17 S
7 18 C
7 19 C
7 20 R
7 21 S
7 22 S
7 23 S
7 24 S
7 25 C
7 26 S
7 27 S
7 28 S
7 29 C
7 30 S
8 1 R
8 2 S
8 3 S
8 4 S
8 5 S
8 6 R
8 7 S
8 8 S
8 9 C
8 10 R
8 11 S
8 12 C
8 13 S
8 14 S
8 15 C
8 16 C
8 17 R
8 18 C
8 19 R
8 20 S
8 21 S
8 22 S
8 23 S
8 24 S
8 25 S
8 26 R
8 27 S
8 28 C
8 29 S
8 30 R
The first column are months 6-8, second column is days 1-30 repeated for each month, third are letters S,R,C indicating if weather is Sunny, Rainy, or Cloudy. I am supposed to get this in arrays to run a weather report.
I am lost as to how to get this to read into the arrays I have set up below.
Any suggestions?

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
int main()
{
	const int MTHS = 3, DAYS = 30, STAT = 3;
	
	int month[MTHS], day[DAYS];
	char weatherStatus[STAT];
	ifstream infile;
	// Open file
	inFile.open("RainOrShine.dat");

	// If file open, process it.
	if (inputFile)
	{
		while( inFile >> month >> day >> weatherStatus )
		{
    		// do stuff with the data
		}
		
		// Close file
		inputFile.close();
	}
	else
	{	// Display error message.
		cout << "ERROR: cannot find/read file." << endl;
	}
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
Open file, check if it's opened

Create 3 arrays 90-places-long // for example: int month[90];

For(int x = 0; x < 90; x +=1)
{
make the first integer in the line go into month[x]
make the second integer in the linego into day[x] 
make the third data(char) in the line go into weatherStatus[x]
go to next line
} 


Well, it should be something like this. I am using pseudo-code(kindof) so you know how to do it. Your code is wrong, because you misinterpreted your task. You can get months from 6 to 8, but you get 90 months(as there are 90 rows). Therefore, making const int months equal 3 and then creating array using it has no sense. Check how big is this array, and how big array do you need to store all these months.
Same goes to all other arrays.

If you need to check whether or not you got valid data, you may do it like:
1
2
3
4
5
6
7
8
//...
make the first integer in the line go into month[x]

if month[x] isn't greater then 5 and less then 9
  show error
else 
 do nothing(so it will move on)
//... 


I hope it helped. Good luck!
My instructor said I need to build a 3 by 30 array holding weatherStatus and this wouldn't work. I am still lost. He said the array should use this in the while loop to get the data:
weather[month - adjusment][day - 1] = weatherStatus

I have been reading websites and my book and I do not understand how this works to build the array.
Topic archived. No new replies allowed.