//This is the code that maintains the files integrity.
//It also creates a new file if it needs to and rechecks it every
//game to make sure it is formatted correctly.


    string line;

    int i = 0;
    ifstream ifile("HighScoresList.txt");

    //if the file exists already
    if (ifile) {
	//read all of the text and store it in an array
        while ( ifile.good() ) {
            getline (ifile,line);
            highScores[i] = atof(line.c_str());
            cout << line << endl;

            if(i == 9) {
                i++;
                break;
            }
            i++;

        }
	//add in the new score that was just made, sort list.
        highScores[10] = stateTimer;
        std::sort(std::begin(highScores), std::end(highScores));
        ifile.close();

        ofstream myfile;
        myfile.open ("HighScoresList.txt");

	//only keep the top 10 scores in this list of 11 (because of recent score)
        for(int j = 0; j < i; j++) {
            myfile << highScores[j];
            myfile << "\n";
        }

        myfile.close();        
    }

    //file doesn't exist
    else {
        printf("HighScoresList.txt does not exist, creating file...");        

        ofstream myfile;
        myfile.open ("HighScoresList.txt");
        myfile << stateTimer;
        myfile << "\n";
        highScores[0] = stateTimer;
        
	for(int i = 0; i < 9; i++) {
            myfile << 9999.99;
            highScores[i+1] = 9999.99;
            myfile << "\n";
        }

        myfile.close();
    }