Basic C++ problems

1. If my i=0, i get a correct input for pre_date as a start but when i increased the i, weird output coming out. The years should be 2012-2015.
2. How do i assign ClearDays to one of the string in weatherType?
I've tried to assign it to weatherType[0] but its an error.

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  string weatherType[] = {"Clear","Rain","Partly Cloudy","Scattered Cloudy",
								  "Fog","TStorm","Snow","Overcast"};
	string thedate, type, line;
	int pre_date, ClearDays, SnowyDays, RainyDays;
	double lowTemp = 0, highTemp = 0, totalrain = 0;
	system("cls");
	
	
	ifstream myfile("weather.txt");
		
	if(!myfile.is_open())
	{
		cout <<"Error opening file.";
	}
	else
	{
		while(myfile >> pre_date >> thedate >> type >> lowTemp 
					   >> highTemp >> totalrain)
        {
		for(int i=0; i<2;i++)
			{
								
				totalrain++;
                                double averageMIN = lowTemp++;
                                double averageMAX = highTemp++;	
									  
                   getline(myfile, line); 
			if (line=="") 
			{
			   cout << endl;
			   ClearDays=0; 
			   RainyDays=0;
			   SnowyDays=0;
			}
			else 
			{
			   ++ClearDays; 
			   ++RainyDays;
			   ++SnowyDays;
			}
								
			cout <<"Year: " <<pre_date<< endl;
			pre_date++;
			cout <<"\t Avg. minimum temperature: " 
                             <<averageMIN<<" C" <<endl;
			cout <<"\t Avg. maximum temperature: " 
                             <<averageMAX<<" C" <<endl;
			cout <<"\t Total rainfall: " 
                             <<totalrain<< endl;
			cout <<"\t Days where reported weather is: " << endl;
			cout <<"\t\t Clear       "<<ClearDays<<endl;
			cout <<"\t\t Rain        "<<RainyDays<<endl;
			cout <<"\t\t Snow        "<<SnowyDays<<endl;
								
			}
							
		  }
			
		}
		
				
		return;
Topic archived. No new replies allowed.