no no no.
1 2
|
for(count = 0; count < SIZE && inputFile >> score[count]; count++)
inputFile >> score[count];
|
is wrong. Here's what happens:
1. count = 0;
2. check if 0 < SIZE
3. read an int form inputFile to score[0]
4. check if 2 and 3 are both successful
5. read an int form inputFile to score[0] (again!)
6. count++;
What happens here, is that only every other element is stored in the array. (I'll explain why you get correct result later)
I already gave you the right code: either
for(count = 0; count < SIZE && inputFile >> scores[count]; count++);//yes. here is a ';'. Everything that needed to be done already happened.
or
for(count = 0; count < SIZE; count++) if( !(inputFile >> scores) ) break;
.
Now, the counting:
1 2 3
|
int score_length;
for(score_length = 0; score_length < count; count++)
score_length += count;
|
How did you think of that? All you had to do is
score_length = count
. Let's see why this works. Note that due to previous errors, count is N/2 (where N is the number of elements in file).
1. score_length = 0, so it is < count.
2. score_length += count, so it is == count.
3. count ++ so score_length < count once again.
4. score_length += count, so it is == count*2 == N (the correct size)
5. count ++. now count = N/2+2 and score_length = N so score_length < count returns false and the loop ends.