int num;
do{
cout << "How many values ?";
cin >> num;
cin.clear();
cin.ignore();
if (cin.fail())
{
cout << "value must be interger !" << endl;
cin.clear();
cin.ignore();
}
elseif (num <= 0)
{
cout << "The number must be integer value greater than 0!" << endl;
}
elseif (num == double(num))
{
cout << "Interger value only, no decimal place!" << endl;
}
} while (cin.fail()||num<=0||num==double(num));
i want to validate the input only allow integer, when user input 3.5 or abc or -5 will go to if else statement and show the error msg.
What's wrong with my code?
You will always get en error because your third if statement (line 22) is not actually checking for decimal places, you're only changing your number to double, but it is still the some number.