T
TaiwanNoWhere
// case 1
int Option = 0;
for(;
{
cin >> Option;
switch(Option)
{
case 1:
return Option;
break;
case 2:
return Option;
break;
case 3:
return Option;
break;
default:
cout <<"Please enter the valid input!";
}
}
// case 2
int Option = 0;
do{
cin >> Option;
if(cin.fail())
{
cout << "Error! Please enter integer value! " << endl;
cin.clear();
}
}while(!(Option>=1&&Option<=3));
return Option;
// I have made the two cases to cin valid Option,
// but both re-cin cannot work when loop repeats.
// Can anyone explain to me the reason?
// I have read the function of clear()
// and still do not get how clear(iostate state=goodbit) works.
// Do I need to declare goodbit before I use it?
// My instructor gives this code to me, but still cannot work
// Thanks
int Option = 0;
for(;
{
cin >> Option;
switch(Option)
{
case 1:
return Option;
break;
case 2:
return Option;
break;
case 3:
return Option;
break;
default:
cout <<"Please enter the valid input!";
}
}
// case 2
int Option = 0;
do{
cin >> Option;
if(cin.fail())
{
cout << "Error! Please enter integer value! " << endl;
cin.clear();
}
}while(!(Option>=1&&Option<=3));
return Option;
// I have made the two cases to cin valid Option,
// but both re-cin cannot work when loop repeats.
// Can anyone explain to me the reason?
// I have read the function of clear()
// and still do not get how clear(iostate state=goodbit) works.
// Do I need to declare goodbit before I use it?
// My instructor gives this code to me, but still cannot work
// Thanks