Input Validation Problem

I have a loop that gains a number from the user and stores it in an array. So far, if you enter a character, it denies the character, sets the count back one number, and asks again, rewriting the previous failed attempt. When I attempt to enter a float, it accepts the first number into the array, and then attempts to read the decimal part, which it declines and says that it's not an integer. I want it to be able to realize that the entire number is a float and reject all aspects of it including the integer out front, asking the user for an entirely new input.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const int arraySize = 10;

void getInput(long int userArray[])
	{
		long int testValue = 0;
		for (int count = 0; count < arraySize; count++)
		{
			cout << "Enter an integer number between -2,147,483,648 and 2,147,483,648" << endl;
			if (!(cin >> testValue))
			{
				cin.clear();
                                cin.ignore(1000,'\n');
				cout << "That is not an integer" << endl;
				userArray[count] = 0;
				--count;
			}
			else
			{
				userArray[count]=testValue;
			}
		}
	}
I want it to be able to realize that the entire number is a float and reject all aspects of it including the integer out front, asking the user for an entirely new input.
I am afraid there is only one way: get input as a string, make sure that all characters are digits and if so, parse number as string:
1
2
3
4
5
6
7
8
9
//std::cin >> str;

//http://en.cppreference.com/w/cpp/algorithm/all_any_none_of
//http://en.cppreference.com/w/cpp/string/byte/isdigit
if(std::all_of(str.begin(), str.end(), ::isdigit)) {
    userArray[count] = std::stoi(str); //http://en.cppreference.com/w/cpp/string/basic_string/stol
} else {
    //...
}
Thank you so much for your reply!
Topic archived. No new replies allowed.