Program logic not working..
Hello,
I am am writing a program that reads in data for a student record (first name, middle initial, last name, student id, etc) and then displays it on the screen for a report. Nothing fancy, just our first program assignment using structured data. Here are parts of my program:
// Type declarations
enum GenderType {MALE, FEMALE};
enum RegistrationType {T, M, U};
struct StudentRecord
{
char FirstName[31];
char MiddleInitial;
char LastName[31];
int StudentID;
GenderType Gender;
RegistrationType Registration;
float GPA;
};
StudentRecord Student;
void InputStudentID( StudentRecord& ); // Prototype for the InputFirstNamefunction
InputStudentID(Student);
void InputStudentID(StudentRecord& aStudent) // Function heading
{
do
{
cout << endl << "Enter Student's ID #: ";
// cin.clear();
cin >> (aStudent.StudentID);
if ((!cin) || (!(aStudent.StudentID >= 1000) && (aStudent.StudentID
<= 9999999)))
{
cout << endl << "The Student's ID # must be numeric and be between
4 - 7 digits long."
<< endl << "Please enter the amount again." << endl;
cin.ignore(10, '\n');
}
}
while ((!cin) || (!(aStudent.StudentID >= 1000) && (aStudent.StudentID
<= 9999999)));
return;
}
Basically what is happening here is I am trying to keep the user from entering any value other than a numeric value and within the range of 1000 to 9999999. The loop should keep repeating until the user keys in a correct value. When I type in the following:
9999A
999999A
it SHOULD error out but instead it quits the entire program. I am using the notation "if (!cin)..." in order to check for numerics. For some reason, this is not working correctly or if it it, I can't see why it's quitting my program when I type in these two values.
Can someone see where my logic is messed up? Thanks!