I have to read in data from a file. This file has 93 lines in it. I need to store these numbers into a 3-dimensional array. The data file layout is like this:
Low Hi <---- not in dat file....
55 80
56 78
58 84
50 81
36 66
46 76
52 74
50 65
... ...
I would like to know why the code below does not print out 2 integers.
Any help would be greatly appreciatedCode:#include <iostream.h> #include <fstream.h> #include <stdlib.h> const int months=3; const int days=31; const int hiLo=2; ifstream infile; int main() { int selNum=0; int numbers[months][days][hiLo]; infile.open("weather.dat", ios::nocreate); if(!infile) { cout << "error" << endl; exit(1); } for(int i=0;i<months;i++) for(int j=0;j<days;j++) for(int k=0;k<hiLo;k++) { infile >> numbers[i][j][k]; } cout << endl << endl << "check this out\n";//display low & high value temp for(i=0;i<months;i++) for(int j=0;j<days;j++) for(int k=0;k<hiLo;k++) { //cout << numbers[i][j][k] //<< endl; } selNum=numbers[3-1][2-1][hiLo]; cout << endl << selNum << endl;// wrong return 0; }