1
0

not.cpp 669 B

123456789101112131415161718192021222324252627282930
  1. // not.cpp -- using the not operator
  2. #include <iostream>
  3. #include <climits>
  4. bool is_int(double);
  5. int main()
  6. {
  7. using namespace std;
  8. double num;
  9. cout << "Yo, dude! Enter an integer value: ";
  10. cin >> num;
  11. while (!is_int(num)) // continue while num is not int-able
  12. {
  13. cout << "Out of range -- please try again: ";
  14. cin >> num;
  15. }
  16. int val = int (num); // type cast
  17. cout << "You've entered the integer " << val << "\nBye\n";
  18. // cin.get();
  19. // cin.get();
  20. return 0;
  21. }
  22. bool is_int(double x)
  23. {
  24. if (x <= INT_MAX && x >= INT_MIN) // use climits values
  25. return true;
  26. else
  27. return false;
  28. }