Skip to content

Instantly share code, notes, and snippets.

@csknk
Created May 12, 2020 19:46
Show Gist options
  • Save csknk/61bf9826a80ddd200ec2cedf98795695 to your computer and use it in GitHub Desktop.
Save csknk/61bf9826a80ddd200ec2cedf98795695 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <limits>
int main() {
int input = 0;
while (1) {
std::cout << "Enter a number (-1 to quit): ";
if (!(std::cin >> input)) {
std::cout << "You entered a non-numeric value..." << std::endl;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
continue;
}
std::cout << "You entered " << input << '\n';
if (input == -1) break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment