有人可以帮我用C ++调试此问题吗? 如果用户要再次输入,我希望它循环播放,但是错误不断出现。
void typeA(){
int j;
char dec;
do{
cout << "Enter Month: ";
cin >> month[j];
cout << "Enter Date: ";
cin >> date[j];
cout << "Enter Time in Hour: ";
cin >> aHours[j];
cout << "Enter Time in Minutes: ";
cin >> aMins[j];
cout << "Enter Time Out Hour: ";
cin >> aHours[j];
cout << "Enter Time Out Minutes: ";
cin >> aMins[j];
cout << "Enter Again?: [y/n]";
cin >> dec;
}while(!dec.compare('y'));
cout << "Exit";
}
答案 0 :(得分:1)
您应该使用==
运算符来检查两个fundamental types是否相等,因为C ++中的基本类型不能具有方法。
void typeA(){
int j;
char dec;
do{
cout << "Enter Month: ";
cin >> month[j];
cout << "Enter Date: ";
cin >> date[j];
cout << "Enter Time in Hour: ";
cin >> aHours[j];
cout << "Enter Time in Minutes: ";
cin >> aMins[j];
cout << "Enter Time Out Hour: ";
cin >> aHours[j];
cout << "Enter Time Out Minutes: ";
cin >> aMins[j];
cout << "Enter Again?: [y/n]";
cin >> dec;
}while(dec == 'y');
cout << "Exit";
}