What is wrong with this function?
// /////// //
void GetData(int(IDs)[], float(Scores)[][4], int &i) {
//GIVEN: One blank ARRAY, one blank 2D ARRAY, & a index variable.
//TASK: Function retrieves data from open stream into multiple functions. Stores ID into one structure and all of the student's test grades into another (two-dimensional) structure.
//RETURNS: Index variable & two ARRAYS now holding relevant information.
ifstream text("data3.txt", ios::in); //Opendata3.txt for read-in through the <fstream.h> class.
do //Do while loop is used to place data
{ //from open stream into storage.
text>>IDs[i];
text>>Scores[i][i];
text>>Scores[i][i+1];
text>>Scores[i][i+2];
text>>Scores[i][i+3];
i++;
} while(IDs[i-1]>0);
i-=2;
text.close(); //Closes open stream.
}
data format in 'data3.txt' consists of records, first line being the student's 4 digit id number and the second being his four test grades. i.e:
2148
90.0 85.0 85.3 42.9
4248
24.2 66.0 89.5 96.0
and so on with about 45 records total.
after executing the function and continuing on (in a different function) to output that stored data this function is supposed to read-in, i get this:
(the problem outlined in red)
Test scores retreived from 'data3.txt':
StudentID Test 1: Test 2: Test 3: Test 4:
#1118647091 66.8 90.9 87.7 65.6
#1117546086 99.5 88.8 55.9 94.5
#8703 88.8 77.6 66.6 89.9
#1110835200 90.4 77.3 72.2 68.8
#1113718784 77.2 77.8 88.3 83.2
#1107977830 55.9 89.9 82.2 84.6
#1113482854 98.8 93.5 94.1 90.2
#1108 89.9 33.5 76.4 67.1
#1117611622 66.5 55.7 55.8 44.9
#1117336371 88.9 88.0 81.4 82.4
#1117415014 66.7 56.8 71.2 65.9
#1116654797 55.5 66.6 66.2 62.1
#6713 67.3 77.8 65.9 87.2
#1114741146 99.3 92.2 87.8 90.3
#1119210701 66.1 62.6 54.1 45.2
#1119918490 55.4 34.4 23.4 77.1
#1117480550 77.4 66.8 75.5 75.2
#8718 80.3 78.9 71.4 62.2
#3319 77.8 77.9 72.4 80.1
#9820 99.9 89.9 99.9 94.6
#1921 66.7 77.1 76.6 79.3
#8822 88.2 82.2 78.9 68.3
#4523 98.3 89.3 78.4 99.4
#7324 77.9 34.7 78.9 78.4
#5425 56.6 45.6 34.5 23.8
#6526 66.7 56.2 78.9 55.9
#9927 92.3 92.3 94.3 80.2
#6228 90.9 88.3 88.8 91.1
#2829 76.8 87.4 87.1 79.3
#5830 55.8 89.9 78.2 90.3
#6831 66.8 90.9 58.4 69.4
#6732 69.9 78.7 50.2 67.5
#7733 77.9 71.2 76.7 75.3
#5234 82.2 81.9 72.6 75.6
#2335 98.3 87.3 93.7 89.2
#1936 77.3 66.3 74.8 50.6
#6737 66.2 67.3 72.1 45.6
#8538 88.8 59.2 67.7 90.5
#5639 55.5 66.6 54.5 59.9
#8840 77.8 98.2 88.3 78.5
#8641 88.8 67.8 86.6 78.2
#1042 45.5 56.5 34.6 55.6
#6343 78.7 76.6 77.2 71.4
#9244 60.4 90.9 96.3 77.7
*all the test data is correct and correct in regards to where in the list it should be. however the student id's (in areas outlined in red) are completely off-base. why is it reading in data half-correctly for the first bit of the file and then completely correctly for the second bit?