Q:

What if user inputs float in integer variable?

int number, number2, number3;

cout << "Enter a number: ";
while(!(cin >> number))
{
    cout << "Wrong input! Enter a number: " << endl;
    cin.clear();
    cin.ignore(INT_MAX,'\n');
}
cout << "Enter number2 and number3: ";
cin >> number2;
cin >> number3;

Output:
Enter a number: 2.345
Wrong Input! Enter a number:
Enter number2 and number3: 

The program ignores the input of number2 and number3 when I enter float number.
How to handle this???

A:

When you are using (cin>>number) as a condition, it will only be false if you enter a non-digit character. So in your case even if you enter a float, it will be false and the value of number = 2 (incase you enter 2.45).
Now the issue that you are facing is solved as follows : 
int main(){

        int number, number2, number3;

        cout << "Enter a number: ";
        while(!(cin >> number))
        {
            cout << "Wrong input! Enter a number: " << endl;
            cin.clear();
            cin.ignore(INT_MAX,'\n');
        }
        cout << "Enter number2 and number3: ";
        cin.clear();
        cin.ignore(INT_MAX,'\n');
        cin >> number2; cin >> number3;
        return 0;
}

This may be because it still has the some value in the input stream as it is not cleared, and it will pick that for number2 and number3.If I am using the above code as it is without cin.clear() and cin.ignore(INT_MAX,'\n') after the while loop, I am getting number2=0 and number3=0 as follows :
Enter a number: 2.45
Enter number2 and number3: 
Value in number : 2
Value in number2 : 0
Value in number3 : 0 

Not sure about it myself as well .Got the following output with this :
int main(){

        int number, number2, number3;
        string temp;
        cout << "Enter a number: ";
        while(!(cin >> number))
        {
             cout << "Wrong input! Enter a number: " << endl;
             cin.clear();
             cin.ignore(INT_MAX,'\n');
        }
        std::getline(std::cin, temp);
        cout << "Enter number2 and number3: ";
        // cin.clear();
        // cin.ignore(INT_MAX,'\n');
        cin >> number2; cin >> number3;
        cout<<"Remaining in cin : "<<temp<<"\nValue in number : "<<number<<"\nValue in number2 : "<<number2<<"\nValue in number3 : "<<number3;
        return 0;
}

Output :
Enter a number: 2.45
Enter number2 and number3: 2
3
Remaining in cin : .45
Value in number : 2
Value in number2 : 2
Value in number3 : 3 

I hope someone could clear my doubt as well. Hope it was helpful.

