I am trying to loop through a file containing the numbers 3.8, 2.1, 2.9, 3.1, 2.0, 1.6, 3.5, 2.3, 2.1, 3.7, and 3.2 and store them in an array. I then have to add those numbers and take the average of that. I have to use a while loop that loops until the end of file, but it is storing the wrong values in the array.
I have tried changing the order statements in the while loop, but it wont do anything. I have changed the file too and it did not help. I believe that it is in the while loop where it is messing up.
subscript = 0;
double gpasummer[subscript];
fin >> gpa;
while (!fin.eof())
{
gpasummer[subscript] = gpa;
fin >> gpa;
subscript = subscript +1;
}
It should output the numbers in the file in the same order and then the average, but it only shows 3.8, 2.3, 2.3, 3.7, 3.2 and 0.0 (Which isnt even in the file), which makes the average wrong.