我的循环运行良好,直到我输入性别的最后一个值为“true”时,循环会忽略剩余循环的cin,并只打印cout中的文本,直到循环结束,有什么办法让循环在每次循环时都要求输入或者我在哪里犯了错误? PS:这是一项学校作业,所以我无法更改给定的结构。感谢任何建议。代码片段如下:
int main()
{
struct Patient
{
double height;
double weight;
int age;
bool isMale;
};
Patient ListOfPatients[4];
int iii = 0;
while (iii < 4)
{
cout << "enter the height (eg. 1.80 metres) of patient number " << iii + 1 << " :" << endl;
cin >> ListOfPatients[iii].height;
cout << "enter the weight (eg. 80kg) of patient number " << iii + 1 << " :" << endl;
cin >> ListOfPatients[iii].weight;
cout << "enter the age of patient number " << iii + 1 << " :" << endl;
cin >> ListOfPatients[iii].age;
cout << "is the patient a male? (true = male or false = female) " << endl;
cin >> ListOfPatients[iii].isMale;
iii++;
}
return 0;
}