// optionMenu = getMenuOption(); // // while(optionMenu > -1){ // switch(optionMenu){ // case 1: // addJob(h, j); // break; // // case 2: // retrieveJob(h, j); // break; // // case 3: // cout << "Option 3..." << endl; // break; // // case 4: // cout << "Option 4..." << endl; // break; // // case 5: // cout << "Bye!"; // exit(0); //terminate program // break; // // default: // cout << "ERROR! Invalid option! Please try again..." << endl; // break; // } // // optionMenu = getMenuOption(); // } int getMenuOption(){ int menuOption=0; cout << "Please enter number to select: "; cin >> menuOption; //error check while(!cin.good()){ //report problem when user input in not numeric cout << "ERROR! Faulty input! Please try again..." << endl; //clear stream cin.clear(); cin.ignore(INT_MAX, '\n'); //get input again cout << "Please enter number to select: "; cin >> menuOption; } //clear stream cin.clear(); cin.ignore(INT_MAX, '\n'); return menuOption; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter