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.
#include <iostream>//
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>
usingnamespace 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
}
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.