I've been missing a lot, but IDK why
swolff's OP is missing or why his account is limited.
Unless he's an obvious pseudo for someone else, I don't see that he has done anything wrong.
That, and the question is a very good one that gets asked frequently.
The answer depends on your UI design -- expectations for the user.
The most correct answer, IMHO, is that your program should ask the question. If the question is incorrectly answered, it should either exit gracefully or back up to a reasonable state.
For example, suppose you have a standard homework scenario where you must maintain a list of students. Each student gets a name (first and last), a school ID, a list of grades, and, IDK, a boolean flag to indicate whether or not he/she is matriculated:
1 2 3 4 5 6 7 8
|
struct Student
{
std::string last_name;
std::string first_name;
std::string id;
std::vector <double> grades;
bool is_matriculated;
};
|
Now, when you write the code to ask the user to input a student's information, you may wish to ask:
Is <name> matriculated (Y/N)?
According to my advice above, if the user does not answer with a clear yes or no, that is an input failure. Rather than simply crash the entire program,
continue the student entry and return to the main menu without adding the invalid student.
What this does is allows
non-human actors to correctly execute your program without problems.
A good way to implement this is to create a method that inputs a student and a
separate method that
validates a student. A useful helper may use both to decide whether to add the new student to the list of students or simply complain that the student was invalid.
Hope this helps.