What happens when you do fin>>X in the condition is the same as anywhere else; if you look at your loop body you will notice that each loop are you are reading into mid twice! Once on line 8 and again on line 11.
Looking at your code from your initial post, you could replace:
Because eof() isn't set to be false until you have tried and failed to read from the file; when you try and fail in your original code, it tries to print after then as well.