So, I am currently having 2 issues with my code.
Problem 1: Any value entered in for the GPA that isn't a number causes an infinite loop. (example: enter in the letter X) Instead of giving an error message, it just goes into that infinite loop.
bool right = false;
while(!right)
{
cout << "4) GPA : ";
cin >> mGPA;
if(mGPA)
{
if(mGPA < 0 || mGPA > 4)
cout << "GPA MUST BE WITHIN RANGE! (0 to 4)" << endl << endl;
else
right = true;
}
else
cout << "GPA ENTERED WAS NOT A NUMBER!" << endl << endl;
}
I'm open to alternatives on that.
Problem 2: If a user is selecting an option from the menu, if it's another number (ex: 6) or a letter (ex: x) it just ends the program rather than saying it's invalid and going back to display the menu again.
do
{
cout << "MENU" << endl;
cout << "1. Create New Student" << endl;
cout << "2. Delete Student (by ID Number)" << endl;
cout << "3. Display All Students" << endl;
cout << "4. Search for Student (by ID Number)" << endl;
cout << "5. Quit" << endl;
cout << "Which would you like to do? ";
cin >> menuChoice;
//#############CREATES A NEW STUDENT IN THE ARRAY###################
if (menuChoice == 1)
{
......
}
//#############DELETES A STUDENT IN THE ARRAY###################
else if (menuChoice == 2)
{
......
}
//#############DISPLAYS ALL STUDENTS IN THE ARRAY###################
else if (menuChoice == 3)
{
......
}
//#############SEARCHES ARRAY FOR ONE STUDENT IN PARTICULAR###################
else if (menuChoice == 4)
{
........
}
//#############QUITS THE PROGRAM###################
else if (menuChoice = 5)
{
term = 1;
}
else
cout << "Please enter in a correct menu choice!";
}while(term == 0);
Again, open to any suggestions to amend these issues.
Thanks again.