{
ofstream output_file;
output_file.open("output.txt");
if (output_file.fail()) {
cout << "\n The output file was not successfully opened"
<< "\n Please check that the path currently exists." <<endl;
exit(1);
}
ifstream input_file;
input_file.open("data51.txt");
if (input_file.fail()) {
cout << "\n The input file was not successfully opened"
<< "\n Please check that the path currently exists." <<endl;
exit(1);
}
if (x < min)
{
min = x;
}
else if (x > max)
{
max = x;
}
}
count++;
tot=tot + x;
}
if (count > 0)
myfile.close();
avg=tot/(float)count;
{
for (i = 0; i < count; i++)
{
sumDiffSqr = sumDiffSqr + pow((i - avg), 2);
}
standev = sqrt(sumDiffSqr / count);
}
output_file << "Number of numbers is: " << count << endl;
output_file << "Total of numbers is: " << tot << endl;
output_file<< "Average of numbers is: " << avg << endl;
output_file << "Max of numbers is: " << max << endl;
output_file << "Min of numbers is: " << min << endl;
output_file << "Standard Deviation of numbers is: " << standev << endl;
What if myfile was not open correctly?
Also: while (myfile). If myfile was in valid state when you enter the loop, it will remain that way forever, as nothing change its state inside loop. So you got an infinite loop.