the loop does not work with the .eof() and i was wondering why not. it doesnt print anything. my program has to be able to find the averages of students and the number of students has to be able to change in txt file.
It will never signal EOF because you never try to read from the file in your for loop.
BUT, the for loop will actually never execute, because the file is already at EOF after you exit the while loop.
Lines 14-22 read the file's data into your arrays. You might as well just close the file on line 23 and be done with it.
Then on lines 24-33 just count through your arrays. You already know how many students there are (by line 23 stu is the number of students), so you can use that to know when to stop.
Thoughts for the future: What happens if there are more than 40 students in the file?