/* testio3.cpp CIS 150 6/5/2008 David Klick This program demonstrates data validation using the switch selection structure. */ #include using std::cout; using std::cin; void cont(); int main(void) { char ch; bool error = false; cout << "Enter the letter 'Y': "; cin >> ch; switch (ch) { case 'y': case 'Y': cout << "Thank you\n"; break; default: cout << "Invalid character entered\n"; error = true; } if (error) { cout << "Abnormal program termination\n"; } else { cout << "Normal program end\n"; } cont(); return 0; } void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press enter to continue..."; cin.get(); }