The do...while loop works fine when i key in only single character, however if i key in multiple characters, the default statement is executed infinitely. I think the problem lies in cin >> int?, i need some help in modifying the code, thx
bool rightanswer = true;
do
{
int choice;
cout << "Gender: \n"
<< "1 - Male \n"
<< "2 - Female" << endl;
cin >> choice;
fflush(stdin);
switch (choice)
{
case 1:
gender = "Male";
break;
case 2:
gender = "Female";
break;
default:
cout << "Wrong selection, please try again" << endl;
rightanswer = false;
}
}while (rightanswer == false);