1while( ! cin >> x){ //While cin failed to stream the data; Reads input then checks if cin has failed
2//Alternative:
3/*
4cin >> x;
5while(cin.fail()){
6*/
7 cin.clear(); //Reset the flags, so you can use cin again
8 cin.ignore(100, '\n'); //Empty the buffer
9 cout << "Please enter a number!\n";
10/* If alternative is used:
11 cin >> x; //Read input again
12*/
13}