I have written a code about guessing a secret number, but I have a problem when an alphabetic character is given as an input instead of an integer. It halts the program. What how can I resist this problem.
srand(time(0));
int a,secret;
secret=rand() % 10 +3;
do{
cout<<"Guess the secret num between 1-10 + 3 : ";
cin>>a;
else if(a>secret)
{
cout<<"Secret num is smaller!!"<<endl;
}
else if(a<secret) {
cout<<"Secret num is greater !!"<<endl;
}
}
while(a!=secret)
cout<<" "<<endl;
cout<<""<<endl;
cout<<"Congratulations!!!! This is the secret num...."<<secret<<endl;