Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <limits>
  3. int main()
  4. {
  5.   int age = 0;
  6.   while ((std::cout << "How old are you? ")
  7.          && !(std::cin >> age)) {
  8.     std::cout << "That's not a number; ";
  9.     std::cin.clear();
  10.     std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  11.   }
  12.   std::cout << "You are " << age << " years old\n";
  13.   // ...
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement