【发布时间】:2019-08-03 03:02:12
【问题描述】:
我的循环运行良好,直到我输入最后一个值作为性别的输入,当输入“true”时,循环忽略其余循环的 cin,只在 cout 中打印文本,直到循环结束,任何想法如何让循环在每个循环上都要求输入,或者我在哪里犯了错误? ps:这是功课,所以我不能改变给定的结构。感谢您的任何建议。代码sn-p:
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;
}
【问题讨论】:
-
en.cppreference.com/w/cpp/io/manip/boolalpha 这将允许您输入“真/假”。