My problem is when I ask the user for the file they want to open if they type it in correctly the first time it breaks out of the while loop and goes on as planned.
However, when they type in a file that cant be opened it tells them to try again and prompts them again but after that first mistake EVEN IF you put in the correct file it will not find it and it is stuck in the loop.
//---ASK USER FOR FILE
void getWords(ifstream& inFile, string wordList[]){
string fileName;
//prompt user until file is found
do{
if (!inFile)
{
cout << "File does not exist, please try again.\n";
inFile.close();
}
cout << "Please enter the name of the file with the word list: ";
cin >> fileName;
//attempt to open
inFile.open(fileName.c_str());
}while (!inFile);
//load file into array
loadWordList(inFile, wordList);
}