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
#include
#include
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;
}
No comments:
Post a Comment