I am making a menu for a console program (a homework assignment). The menu is set up so that the use may enter an int 1-9 but when they enter an int outside the 1-9 range they get an "Invalid Entry" messege.
Currently, if I try to enter a non-int character or a string the program crashes. My question is how do I make it so the program filters out non-int entries?
Here is my code...
Code:#include <iostream> using namespace std; int main(){ int selection; cout << "Please select from the following:\n\n" << "1. Add Customer\n" << "2. Delete Customer\n" << "3. Change Customer Name\n" << "4. Rent Video\n" << "5. Return Video\n" << "6. Renew Video\n" << "7. Report Overdue Videos\n" << "8. Report Checked Out Videos\n" << "9. Search for Customer\n\n"; cin >> selection; cin.get(); if( selection < 1 || selection > 9 ) cout << "Invalid Entry"; else cout << "Valid Entry"; return 0; }



LinkBack URL
About LinkBacks


