When I run my program it works the first time, the correct input is read and output is written to my output file but once I run it a second time it doesn't write anything the file is just blank even though it reads everything correctly. I can't seem to understand where its messing up or how and I really want to know. The two images are my first and second runs just that after the second run my output file is blank.
#include<iostream>
#include<iostream>
#include<cstdlib>
#include<time.h>
#include<fstream>
#include<string>
using namespace std;
int main()
{
    int i=0;
    int number; // The correct number
    int guess=0;  // The user's guess
    int numGuesses=0; // The number of times the user has guessed
    string lines;
    string player;
    ifstream ifile;
    ofstream ofile;
    //ofstream myfile;
    //
    string names[10];
    int scores[10];
    ifile.open("high_score.txt");
    string first_last_name;
    string temp;
    int score;
    int index=0;
    string title;
    bool topten=false;
    cout <<"Welcome to the number guessing game. The top 10 best scores so far are: "<<endl;
    while(!ifile.eof())
    {
        //getline(ifile,lines);
        ifile >>first_last_name;
        //cout << first_last_name;
        ifile >> temp;
        first_last_name.append(" ");
        first_last_name.append(temp);
        ifile >> score;
        names[index]=first_last_name;
        scores[index++]=score;
    }
    cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
    for (int i=0; i < 10; i++)
    {
        cout << names[i] << " " << scores[i] <<endl;
    }
    // Seed the random generator.
    srand(static_cast<int> (time(NULL)));
    // Generate a random number between 1 and 100.
    number = (rand() % 100) + 1;
    cout << "Let's play the number guessing game! What is your name? " <<endl; 
    getline(cin,player);
    cout << endl;   
    while(guess!=number)
    {
        cout << "guess the number the computer randomly picked between 1 - 100: ";
        cin >> guess;
        numGuesses++;
        // Check if the user has guessed the correct number.
        // If not, tell him if his guess is too low or too high
        if(number > guess)
        {
            cout << "sorry, your guess is too low" << endl;
        }
        else if(number < guess)
        {
            cout << "sorry, your guess is too high" << endl;
        }
        else
        {
            cout << "You guessed right!!!!"<<endl;
            cout << "You win!!!" << endl;
            break;
        }
    }
       cout << "It took you "<< numGuesses << " guesses "<< player<< endl;
////////////////////////////////////////////////////////////////////////
       if (numGuesses<4)
       {
       cout << "Amazing! Or was it luck" << endl;
       }
       else if(numGuesses<6)
       {
           cout <<"That's a very good score..." <<endl;
       }
       else if (numGuesses<8)
       {
        cout << "That's pretty good but you can do better..." << endl;
       }
       else if ( numGuesses<10)
       {
       cout << "Not too shabby, but not too good either..."<< endl;
       }
       else
       {
       cout << "What a terrible score!..." << endl;
       }
    for(int i=0; i < 10; i++)
    {
        if(numGuesses <= scores[i])
        {
            for( int k=9;k>i;k--)
            {   
                scores[k]=scores[k-1];
                names[k]=names[k-1];
            }
            scores[i]=numGuesses;
            names[i]=player;
            topten=true;
            break;
        }
    }
    if(topten==true)
    {
        cout << "Hey, you made it to the top ten , Congratzzzzzzzz!!!!" <<endl;
    }
    ofile.open("high_score.txt");
    for(int i=0;i<10;i++)
    {
        ofile <<"\t"<< names[i] << " " << scores[i] <<endl;
        ofile << endl;
    }
    return 0;
}
 
     
    