This is just a portion of my program. My problem is that my program doesn't trap or block character inputs. I declare char opt='0' to go to main menu. If the user inputs a character the user must input again. How to trap it.
case'2':
{
if(y==1)
{
view();
}
else
{
system("cls");
cout<<"\n\n\t\t------------------------------\n\n";
cout<<"\t unable to view the record!!!!";
cout<<"\n\n\t\t------------------------------\n\n";
int v=1;
while(v!=0&&!cin&&cin.fail()) //I used this for trapping a chararacter but it doesn't work.
{
cout<<"press 0 to go menu: ";
cin.clear(); // clear the error
// clear the input stream
cin.ignore(100,'\n');
cin>>v;
}
system("cls");
}
break;
}
this is the wrong output of my program when I input a character
press 0 to go menu:press 0 to go menu:
press 0 to go menu:press 0 to go menu:
press 0 to go menu:press 0 to go menu:
press 0 to go menu:press 0 to go menu:
press 0 to go menu:press 0 to go menu:
press 0 to go menu:press 0 to go menu:
press 0 to go menu:press 0 to go menu: