Hello, I am having problem with my do...while loop. It asks for student identifier twice before proceeding. I tried moving the "do" after the program prompts the user for his choice of id, but I couldn't get the loop to terminate after that. Any tips will be appreciated. Thank you!
do
{
cout << "Please enter a student indentifier from the list (or 'E' to exit): ";
cin >> studentId;
length = studentId.length();
for (int index = 0; index < NUM_STUDENT_INITIALS; index++)
studentId[index] = toupper(studentId[index]);
if ((length == 1) && (studentId[0] == 'E') || (studentId[0] == 'e'))
{
cout << endl << "You have choosen to exit the program. Have a nice day."
<< endl << endl;
return;
}
else if (length > LENGTH_STUDENT_ID)
{
cout << "I'm sorry, " << studentId << " is too long. Please choose a"
<< " a correct identifier from the list. All indentifiers are"
<< " three letters followed by one number." << endl << endl;
cout << "Enter the student identifier (or 'E' to exit): ";
cin >> studentId;
}
else if (length < LENGTH_STUDENT_ID)
{
cout << "I'm sorry, " << studentId << " is too short. Please choose a"
<< " a correct identifier from the list. All indentifiers are"
<< " three letters followed by one number." << endl << endl;
cout << "Enter the student identifier (or 'E' to exit): ";
cin >> studentId;
}
else if (index == 0)
{
while (index < NUM_STUDENT_INITIALS)
{
if((studentId[index] != 'A' ) && (studentId[index] != 'B') &&
(studentId[index] != 'C' ) && (studentId[index] != 'D') &&
(studentId[index] != 'E' ) && (studentId[index] != 'F') &&
(studentId[index] != 'G' ) && (studentId[index] != 'H') &&
(studentId[index] != 'I' ) && (studentId[index] != 'J') &&
(studentId[index] != 'K' ) && (studentId[index] != 'L') &&
(studentId[index] != 'M' ) && (studentId[index] != 'N') &&
(studentId[index] != 'O' ) && (studentId[index] != 'P') &&
(studentId[index] != 'Q' ) && (studentId[index] != 'R') &&
(studentId[index] != 'S' ) && (studentId[index] != 'T') &&
(studentId[index] != 'U' ) && (studentId[index] != 'V') &&
(studentId[index] != 'W' ) && (studentId[index] != 'X') &&
(studentId[index] != 'Y' ) && (studentId[index] != 'Z'))
{
cout << endl
<< "I'm sorry, student identifier " << studentId << " is formatted"
<< " incorrectly. All" << endl << "indentifiers are three letters"
<< " followed by one number. Please" << endl << "try again."
<< endl << endl;
cout << "Enter your account number (or 'E' to exit): ";
cin >> studentId;
index = NUM_STUDENT_INITIALS;
}
else
{
index++;
}
}
}
else if (!(studentId[index] > 0))
{
cout << endl
<< "I'm sorry, student identifier " << studentId << " is formatted"
<< " incorrectly. All" << endl << "indentifiers are three letters"
<< " followed by one number. Please" << endl << "try again."
<< endl << endl;
cout << "Enter your account number (or 'E' to exit): ";
cin >> studentId;
}
else
looping = false;
} while (looping);