Why do letters loop a cin function when the function asks for an integer?
https://code.sololearn.com/cMp7TOffT1T0/?ref=app cout<<"{1 Yes}\n{2 No}\n"; //The choices. cin>>namE; //The variable for the number choice. while(namE!=1&&namE!=2){ //The while loop that initiates if a person enters a number other than 1 and 2. cout<<"That's not valid.\n"; //Message that displays in the loop. cout<<"{Choose either 1 or 2.}\n"; //Another message. cin>>namE; //Input area again. } int gender; //Declaring the integer variable "gender". cin>>gender; //Input value of "gender". while(gender<1||gender>4){ //Loop just in case input is none of the choices (1, 2, 3, or 4). cout<<"I don't think that's valid.\n"; //Message that displays. cout<<"{Please choose again.}\n"; //Message that displays. cin>>gender; //Input value of "gender" again. } These loops keep going over and over again if anything other than an integer is input in the code. Why does it do that and what can I do to prevent this from happening? That is, what can I do so that it loops only once every single invalid input?