// Example of re-validating CIN // // George Cross, Borland C++ Developer Support, April 1997 // // Build with BC++ 5 // // bcc32 -v thisfile.cpp // #include void main() { int x; do{ cout << "Please enter a number greater than zero. "; cin >> x; if (cin.fail()){ cin.clear(); cin.rdbuf()->overflow(); x = 2; //force "Invalid number." } switch (x){ case 0: cout << "Terminating.\n"; break; case 1: cout << "You've entered Sunday.\n"; break; default: cout << "Invalid number. Please try again.\n"; } }while (x > 0); }