One part of my program: Let user input a series of integer, and then put them into an array.
int n=0;
cout<<"Input the number of data:";
cin>>n;
cout<<"Input the series of data:";
int a[50];
for(i=0; i<n; i++)
{
cin>>a[i];
}
Then, when user input wrong data such as a character 'a' or 'b'. The program will go into an infinite loop.
How to catch the wrong cin? How to clear the buffer and give user the chance to input a right data again?