Possible Duplicate:
Why is iostream::eof inside a loop condition considered wrong?
Here is my program it compiles and everything but the while loop with eof becomes infinite the file scores.dat contains a list of 20 random numbers. Why does the eof not work and makes it loop continuously???
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int main ()
{
  int x, sum = 0, count = 0;
  double answer;
  ifstream  y;
  y.open("scores.dat");
  while (!y.eof())
   {
     y >> x;
     sum = sum + x;
     count ++;
     cout << x << endl;
   }
  answer = sqrt (((pow(x, 2.0)) - ((1.0/count) * (pow(x, 2.0)))) / (count - 1.0));
  cout << answer;
}
 
     
    