It looks like your file is organized as:
1 2 3 4 5
|
1 2 3
4 5 6
7 8 9
10 11 12
...
|
You should have a function that handles each day's worth of data in the file with a single function:
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
|
struct OneDaysData_t
{
double sunlight, power_output, temperature;
double total_1, total_2; // what are these?
};
istream& operator >> ( istream& ins, OneDaysData_t& data )
{
for (int k=1; k <= 24; k++)
{
infile >> data.sunlight
>> data.power_output
>> data.temperature;
// more stuff here...
}
return ins;
};
int main()
{
OneDaysData_t monday, tuesday, wednesday, friday;
ifstream weather_data_file( "data.txt" );
...
weather_data_file >> monday;
weather_data_file >> tuesday;
weather_data_file >> wednesday;
weather_data_file >> friday; // (well, this is thursday, we'll read friday next:)
weather_data_file >> friday;
...
// http://www.cplusplus.com/forum/articles/11153/
cout << "Press ENTER to quit." << flush;
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
return 0;
}
|
The code that you posted above should not compile, because you never declare
Data1,
Data2, and
Data3. What are they?
What are
Total and
Total2?
You need to be
specific when you name things. This tells you a lot about what your program should be doing, and what kind of data it is handling.
» "infile" is not a useful name because it tells you nothing about the file you are using. Only use
generic names when handling stuff that could be anything.
» "sunlight" is a very good name because it tells you exactly what it is: whether sunlight was measured.
Likewise, you assume a lot of knowledge about your data in your commentary on lines 29, 23, and 33. How do you know that stuff? (The data your program reads from the file could change!)
Likewise, your commentary is often not very helpful. For example, on line 28 (besides using an uninitialized variable --
sunlight could be -32.7 for all you know -- since you never set its value!), on line 28 you say "Ignores Data 1 if it is 1 or 0". That's nonsense. What you should say is something like "No sunlight means that there is no power output." [Are you working with solar cells or something?]
Hope this helps.