cout << "Machine ID: "; //WHILE LOOP: check whether Machine ID is in numeric while(!(cin >> machineID)){ //display error message cout << "ERROR! Invalid Machine ID! Please try again..." << endl; cout << "Machine ID: "; cin.clear(); //clear previous user input cin.ignore(INT_MAX, '\n'); //discard previous user input }
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