暗証番号の推測に関するコードを書きましたが、整数の代わりに英字が入力として与えられた場合に問題が発生します。プログラムを停止します。どうすればこの問題に抵抗できますか。
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;