#include <iostream>
#include <limits>
#include <cctype>
int main()
{
int age;
char c;
while( !( std::cin >> age ) || ( std::cin.get(c) && c != '\n' ) )
{
std::cout << "invalid input, please try another: ";
std::cin.clear(); //clear the bufer
std::cin.ignore( std::numeric_limits<std::streamsize>::max() , '\n' ); //ignore anything that might be left in the buffer
}
std::cout << std::endl << std::endl << "You entered: " << age << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bGltaXRzPgojaW5jbHVkZSA8Y2N0eXBlPgoKaW50IG1haW4oKQp7CglpbnQgYWdlOwoJY2hhciBjOwoJd2hpbGUoICEoIHN0ZDo6Y2luID4+IGFnZSApIHx8ICggc3RkOjpjaW4uZ2V0KGMpICYmIGMgIT0gJ1xuJyApICkKCXsKCSAgICBzdGQ6OmNvdXQgPDwgImludmFsaWQgaW5wdXQsIHBsZWFzZSB0cnkgYW5vdGhlcjogIjsKICAgIAlzdGQ6OmNpbi5jbGVhcigpOyAvL2NsZWFyIHRoZSBidWZlcgogICAgCXN0ZDo6Y2luLmlnbm9yZSggc3RkOjpudW1lcmljX2xpbWl0czxzdGQ6OnN0cmVhbXNpemU+OjptYXgoKSAsICdcbicgKTsgLy9pZ25vcmUgYW55dGhpbmcgdGhhdCBtaWdodCBiZSBsZWZ0IGluIHRoZSBidWZmZXIKCX0KCQoJc3RkOjpjb3V0IDw8IHN0ZDo6ZW5kbCA8PCBzdGQ6OmVuZGwgPDwgIllvdSBlbnRlcmVkOiAiIDw8IGFnZSA8PCBzdGQ6OmVuZGw7CglyZXR1cm4gMDsKfQ==