This should work
* Edit * - reference link: http://www.cplusplus.com/reference/iostream/istream/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
int main()
{
int value;
std::cout << "Enter 0-9" << std::endl;
std::cin >> value;
while(std::cin.fail())
{
std::cout << "Invalid Entry\nEnter 0-9" << std::endl;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin >> value;
}
std::cout << "Entered: " << value << std::endl;
return 0; //Edit # 2 - Forgot my return !
}
|
Last edited on
Last edited on
thanks Luc Lieber
it works.. but eg, if i entered 11a it will register the 11 in it.
Posting this to tell you that I didn't copy the right url, I edited in the right one into my reply :P