Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <limits>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. main()
  8. {
  9.     int t;
  10.     string s;
  11.     char *end;
  12.  
  13.     while (1) {
  14.         cout << "Enter a number: ";
  15.         cin >> s;
  16.         cin.ignore(numeric_limits<streamsize>::max(),'\n');
  17.         t = strtol(s.c_str(), &end, 10);
  18.                    
  19.         if (t>26 || t<0 || (*end!=0) || s.empty()) {
  20.             cout << "Please enter an integer between 0 and 26.\n";
  21.             continue;
  22.         }                      
  23.        
  24.         cout << "You entered " << t << "\n";
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement