Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int getNumber(char * prompt)
- {
- int num;
- do
- {
- if(std::cin.fail())
- {
- std::cin.clear();
- //std::cin.ignore(1024, '\n'); // 1024 is arbitrary :-/
- while(std::cin.get() != '\n'); // replaced above
- }
- if(std::cin.good())
- {
- std::cout << prompt << std::endl;
- std::cin >> num;
- }
- }
- while(std::cin.fail());
- return num;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement