//***************************************************************************
string userInput()
{
bool goodID = false;
string id = " ";
cout << endl << endl;
cout << "Enter ID number (or enter X to end): " << endl;
cin >> id;
while (id != "X" && !goodID)
{
if (testValidity(id) == true)
{
cout << endl;
cout << "INVALID ID FORMAT" << endl;
cout << "Must start with two characters (A to Z)and end with six digits" << endl;
cout << "Enter ID number (or enter X to end): " << endl;
cin >> id;
}
else
{
cout << endl;
cout << "VALID ID FORMAT" << endl;
goodID = true;
}
}
return id;
}
//***************************************************************************
bool testValidity(string id)
{
bool invalidLetter = false;
for (unsignedint i= 0; i < id.length()-1; i++)
{
if (i > 1 && isalpha(id[i]))
invalidLetter = true;
if (i < 2 && isdigit(id[i]))
invalidLetter = true;
}
if (id.length()!= 8)
invalidLetter = true;
return invalidLetter;
}
My ID number looks like AS123456. That's a valid ID. It should exit when you enter X or x. Thanks again.