I am new to programming, so I have what is probably a basic question. I currently have a text file with 365 lines...one line per day of the year. These are the first four lines of the file:
2003 1 1 18 0 -1 36 50 46
2003 1 2 16 3 -1 43 56 52
2003 1 3 19 7 -1 42 56 49
2003 1 4 14 3 -1 42 58 50
I eventually have to graph these using a special library given to us, but first I want to put the data for each column into an array. This is the part of my code where I attempt to do just that.
#include "library.h"
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream in;
int yr[364], mo[364], day[364], windSpeed[364], precip[364], snowDepth[364], minTemp[364], maxTemp[364], avgTemp[364];
void main() {
make_window(800, 800);
set_pen_color(color::red);
set_pen_width(8);
// open file, read in data
in.open("PORTLAND-OR.TXT");
if (in.is_open()) {
// read each column into an array
for (int i = 0; i < 364; i++) {
in >> yr[i] >> mo[i] >> day[i] >> windSpeed[i] >> precip[i] >> snowDepth[i] >> minTemp[i] >> maxTemp[i] >> avgTemp[i];
cout << mo[i] << " " << day[i] << endl;
}
in.close();
}
else {
cout << "error reading file" << endl;
exit(1);
}
}
When I attempt to print out all of the values in the second and third columns (month and day), it begins printing from march 8 (3 8) through december 31 (12 31). I need it to print all the way from January 1 to December 31. Is there a reason why the first two months worth of values isn't printing?