Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <limits>
- #include <cstdlib>
- using namespace std;
- main()
- {
- int t;
- string s;
- char *end;
- while (1) {
- cout << "Enter a number: ";
- cin >> s;
- cin.ignore(numeric_limits<streamsize>::max(),'\n');
- t = strtol(s.c_str(), &end, 10);
- if (t>26 || t<0 || (*end!=0) || s.empty()) {
- cout << "Please enter an integer between 0 and 26.\n";
- continue;
- }
- cout << "You entered " << t << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement