I am trying to check the input value, and I run this program below. But when I give a wrong input it goes into infinite loop. I tried the cin.clear(); but still it goes to infinite loop. Please can anyone give me a solution for this.
#include<iostream>
using namespace std;
int main()
{
    int c=0;
    cout<<"in test"<<endl;
    //cin.clear();
    cin>>c;
    if(cin.fail())
        {
            cout<<"please try again"<<endl;
            main();
        }
    else
        cout<<"c = "<<c<<endl;
    return 0;
}
 
     
     
    