loop help

I need to set up a loop that will pull a set of data from a text file for example, wet.txt In the text file will contain high and low temperature data, as well as rain accumulations for an unknown amount of days, For example:

low high rain
30 60 0.3
25 55 0
30 65 0

I feel like i'm making this too complicated, I feel like I can put this into just one loop but i'm not sure how. I believe I would be using a while loop because we don't how many days of data their would be.

The output should look like:

Days reported = 3
Min Temp = 25
Max Temp = 65
Avg Low = 28.3
Avg High = 60.0
Total rain = 0.3
Number of rainy days = 1

Pretty much read while it is good(there is data to be read). You can put multiple inputs in each while loop example:

1
2
3
4
5
while(in.good() )
{
    in >> low >> high;
    in >> rain;
}


*link added

http://www.cplusplus.com/reference/fstream/ifstream/ifstream/
http://www.cplusplus.com/doc/tutorial/files/
Last edited on
I was thinking something like

1
2
3
4
while(fin>>low) {
fin>>high>>rain
//I'm not sure what to do here
}
might as well just do
while( fin >> low >> high >> rain )

but it might be better to try

1
2
3
4
while( fin.good() )
{
    fin >> low >> high >> rain; 
}
Topic archived. No new replies allowed.