我的if陈述不是100%有效,我不确定我做错了什么。任何帮助将不胜感激,谢谢!这是我的功能
void DisplayStudentsInRange(const StudentType student[], int numStudents, int lownum, int highnum)
{
cout <<"Enter two values from 0-100 for the range of test scores you want to view: ";
cin >> lownum >> highnum;
if ( lownum < 0 || highnum < 0 || lownum > highnum || lownum > 100 || highnum > 100)
{
cout <<"Please re-enter 2 values of test scores that you want to view from within the range 0-100";
cin >> lownum >> highnum;
}
cout << endl << "List of students with scores in the range " << lownum << " to " << highnum << endl << endl;
FormatNameScoreGrade(cout);
for(int i = 0; i < numStudents; i++)
{
if(student[i].testScore >= lownum && student[i].testScore <= highnum)
{
cout << setw(20) << student[i].studentName << setw(10) << student[i].testScore << setw(10) << student[i].grade << endl;
}
}
cout << endl;
}
最佳答案
我会在您的if语句中使用括号
if ( (lownum < 0) || (highnum < 0) || (lownum > highnum) || (lownum > 100) || (highnum > 100))
过去没有这样做的时候,我遇到了问题。