I want to print out the last 10 numbers in my file, but when i try and print it out, my program prints out the last number inputted 10 times. How do i fix this so it inputs the last 10 numbers instead of just the last number?
else if (option == 2)
{
writefile.open("highscores.txt");
cout << "You have selected '2.' Here are the current highscores" << endl;
for (int i = 0; i < 10 && !writefile.eof(); i++)
{
writefile >> x;
cout << x << endl;
}
Here is the input for the program.
if (option == 1)
{
myfile.open("highscores.txt");
writefile.open("highscores.txt");
myfile << "Top Ten Highscores.\n";
cout << "You have chosen '1.' Please enter 10 scores!" << endl;
for (int i = 0; i < 10; i++)
{
cin >> x;
myfile << x << "\n";
}
cout << "Your number has been entered!" << endl;
myfile.close();
writefile.close();
continue;
}