Hello. Tell me, please, how to check the numbers in the loop, whether they are entered correctly. My method is not suitable, as the values skip. How to deal with these "skips"?
int validIntInput() { int num; while(!(cin >> num)) { cin.clear(); cin.ignore((numeric_limits<std::streamsize>::max)(),'\n'); cout << "Wrong input. Please, try again: "; } return num; }
When typing hex2, the function returns 1, while typing 1.2 - also 1.
I use this:
for(int i = 0; i < COUNT; i++) numbers[i] = validIntInput();
Thank.
cin.eof() == true
). - avp