gpt4 book ai didi

测试分数为 0-100 的 C++ 函数

转载 作者:行者123 更新时间:2023-11-28 00:38:55 25 4
gpt4 key购买 nike

我的 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 语句,您可能希望将输入和验证放在一个循环中:

do {
values = get_input();
} while (!values_are_valid());

关于测试分数为 0-100 的 C++ 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19827199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com