I've read this on some other questions here at DaniWeb so I've been trying to use the suggestions posted. They don't seem to be working correctly for what I need or I'm seriously confused (probably the latter). Anyways, I'd like to establish good programming practices early to avoid developing bad habits.
Here's the code:
int choice;
cin >> choice;
switch(choice) {
case 1:
system("cls");
{
bool userExists = false;
FileController fc;
string tmp;
char getData[50];
while (!fc.getInFile().eof()) {
fc.getInFile() >> tmp;
if (tmp == userName) {
cout << "Welcome back, "<< userName << "!\n\n" << endl;
userExists = true;
fc.getInFile().close();
break;
}
}
if (userExists == false) {
cout << "Great! Let's begin!\n\n" << endl;
}
}
break;
case 2:
. . .
default:
. . .
Essentially. A user inputs a name and are asked if they'd like to continue using the name (int choice). If they choose yes, the program checks if there's a matching username in the file and posts the "Welcome Back" message. Otherwise, the "Let's begin message."
One problem I do see using the .eof right now is the infinite loop I sometimes get when inputting a name that does not exist yet in the file.
Thanks in advance. You all here work wonders and have helped me in the past :)