Help with loops regarding text file

Hello, I have made a previous post solved those issues; however, I would like to keep track of rain days. The data in the text is formatted:
.3
0
0 this means only one day of rain has occurred. If it was:
.5
.6
0 then two days have occurred. I want a statement that will display this. Here is my code lines 48-51 are my attempt.
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
#include <iostream>//
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
	ifstream weatherfile("wet.txt");//allows file to be opened 
	if (!weatherfile)//if statement to check if the file has opened correctly
	{
		cout<<"Please try again, unable to open text file"<<endl;//output if file does not open correctly
		return -1;//return value if so
	}
	int minlow, minhigh;//declaring variables
	int minimumlow=100, minimumhigh=0;//varibables that the above varibales will be set equal to, allows for calculations
	double rain;//variable for rain
	int countrainydays=0;//counts rainy days 
	int countraindays=0;//allows countrainydays to be set equal
	int sumforlowtemp=0;//value holder for lowtemp holds the sum
	int sumforhightemp=0;//value holder for hightemp holds the sum
	double sumforrain=0;//value holder for rain holds the sum
	
	int x=0;//allows the number data in each column to be added by how many entries 
	int b=0;//allows the number data in each column to be added by how many entries 
	int e=0;//allows the data in the rain column to be added, goes by entries 
	int averagelow;//variable for average 
	int averagehigh;//variable for average 
	while(weatherfile>>minlow>>minhigh>>rain)//tells program how data is organized in the file 
	{
		sumforhightemp=sumforhightemp+minhigh;//sum of the high temperatures
		sumforlowtemp=sumforlowtemp+minlow;//sum for the low temperatures 
		sumforrain=sumforrain+rain;//sum for the rain, this is displaying zero, why is that??? 
		x++;//adding the entries 
		b++;//adding the entries
		e++;//adding the entries 
	
		if(minimumlow>minlow)//if statement properly adjusted, to fix this issue had to flip the sign and to set a high value to the statement.
		{
		
		minimumlow=minlow;//sets the minimumlow equal to the actual data 
	}
	if(minimumhigh<minhigh)//this if statement works correctly and displays 65 
	{
		minimumhigh=minhigh;//sets the minimumlow equal to the actual data 
	}
	if(sumforrain>0, countrainydays++)
	{
		countraindays=countrainydays;
		cout<<" Rainy days: "<<countraindays<<endl;
	}
}
	averagelow=sumforlowtemp/x;//calculations for average 
	averagehigh=sumforhightemp/b;//calculations for average 
	cout<<"Days reported: "<<x<<endl; //output of entries or days 
	cout<<"Minimum low temperature: "<<minimumlow<<endl;//output for minimum temperature
	cout<<"Minimum high temperature:"<<minimumhigh<<endl;//output for minimum high 
	cout<<"Average low: "<<averagelow<<endl;//output for average 
	cout<<"Average high: "<<averagehigh<<endl;//output for average 
	cout<<"Total rain: "<<setprecision(1)<<fixed<<sumforrain<<endl;//suppose to display total rain
	
}

Last edited on
The comma separator on line 47 processes the separate statements and evaluates the last. So sumforrain>0 is ignored. I would guess that you want a while loop to count the rainy days.

Line 49 doesn't do anything either.
Topic archived. No new replies allowed.