Maybe someone else can explain why line 35 compiled. AFAIK, that's not a valid statement.
I think it would be a lot clearer to you if you were to move the logic for adding a player out of main to a separate function. Likewise, move the logic for displaying players to a separate function. Now you're left with just the logic in main to prompt for a player and to ask if the user wants to add another player. And as mentioned before, if select is "y", continue your loop to prompt for more players.
bool add_player (char * player, int score)
{ ofstream file ("golf.dat", ios::app);
if (! file.is_open())
{ cout << "failed to open golf.dat" << endl;
returnfalse;
]
file << endl;
file << "player name: " << player << endl;
file << "player score: " << score << endl;
cout << "Successfully added player!" << endl;
file.close();
returntrue;
}
bool display_players ()
{ ifstream readFile;
string golfScore;
readFile.open("golf.dat");
if (! readFile.isOpen())
{ cout << "Couldn't open golf.dat" << endl;
returnfalse;
}
cout << "Here are the records from the golf.dat file:" << endl;
while (readFile >> golfScore)
{ cout << golfScore << endl;
}
readFile.close();
returntrue;
}
The code I've show above opens and closes golf.dat for each addition, but that is a minor inefficiency. It does however guarantee that you don't attempt multiple opens of golf.dat for every player added as was the case with your recursive calls to main.
the if(select=='y') should only run once, try using a while loop so that it runs until you hit anything but 'y', or you can specify a character to hit when you want the loop to stop like 'n'.
They're valid statements because they are valid expressions. None of it wuld compile in Java because Java does no allow statements that have no effect, but C and C++ do allow statements with no effect.
The first three lines are just literal constants with the same types as the next three lines, which explicitly call the default constructor of those types.
Since you made me research this, returnvoid(); is my new favorite obscure obfuscation in C++. Imagine making a type alias for void and then using it for non-returning functions at random, and using the void-return feature a lot. Great way to confuse people about the flow of the code.
Thanks guys I been working on this project for two weeks and is due tomorrow. I have looked at all the advice you guys gave me, but I still cannot get the program to run correctly. I hate to turn it in and get a failing grade but I just cannot figure it out. I do appreciate all the help and I only have one more exercise to do this semester. I'm hoping and praying that I don't have to take this class over again.