C++ C++;我该如何解决这个问题 #包括 #包括 #包括 使用名称空间std; //功能原型 void getScore(int和score、ifstream和infle); 无效平均值(int testScr1、int testScr2、int testScr3、int testScr4、int testcr5); int findLowest(int testScr1、int testScr2、int testScr3、int testScr4、int testScr5); 内部等级(内部测试SCR1、内部测试SCR2、内部测试SCR3、内部测试SCR4、内部测试SCR5); int main() { 河流充填; infle.open(“grades.txt”); int最低=100; int testScr1、testScr2、testScr3、testScr4、testScr5; getScore(testScr1,infle); 如果(testScr1

C++ C++;我该如何解决这个问题 #包括 #包括 #包括 使用名称空间std; //功能原型 void getScore(int和score、ifstream和infle); 无效平均值(int testScr1、int testScr2、int testScr3、int testScr4、int testcr5); int findLowest(int testScr1、int testScr2、int testScr3、int testScr4、int testScr5); 内部等级(内部测试SCR1、内部测试SCR2、内部测试SCR3、内部测试SCR4、内部测试SCR5); int main() { 河流充填; infle.open(“grades.txt”); int最低=100; int testScr1、testScr2、testScr3、testScr4、testScr5; getScore(testScr1,infle); 如果(testScr1,c++,C++,您真的应该尝试使用调试器逐步检查代码,这将有助于验证您的怀疑 然而,你的直觉是正确的。你总是将testScr1分配给lovel。在阅读5个等级时,你已经计算了lovel的值,因此可以放弃该部分并修复findLowest()或放弃findLowest()请在此处格式化您的代码,以便我们阅读。使用调试器,它会准确地告诉您发生了什么。您在main()中找到了最低的值,我不知道您为什么编写了另一个错误的findLowest函数。您自己注意到了问题,它只是输出测试分数1。我必须使用void getScor

您真的应该尝试使用调试器逐步检查代码,这将有助于验证您的怀疑


然而,你的直觉是正确的。你总是将
testScr1
分配给
lovel
。在阅读5个等级时,你已经计算了
lovel
的值,因此可以放弃该部分并修复
findLowest()
或放弃
findLowest()

请在此处格式化您的代码,以便我们阅读。使用调试器,它会准确地告诉您发生了什么。您在main()中找到了最低的值,我不知道您为什么编写了另一个错误的findLowest函数。您自己注意到了问题,它只是输出测试分数1。我必须使用void getScore()读取文件并将其存储在引用参数变量中。main应该为5个分数中的每一个调用此函数一次。我必须使用void calcAverage()计算并显示4个最高分数的平均值。main只需调用此函数一次,并通过五个分数。最后,我必须使用int findLowest()它应该找到并返回传递给它的五个分数中最低的一个。它应该由calAverage调用,calAverage使用函数来确定要删除五个分数中的哪一个。
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

// Function prototype
void getScore(int& score, ifstream& inFile);
void calcAverage(int testScr1, int testScr2, int testScr3, int testScr4, int testcr5);
int findLowest(int testScr1, int testScr2, int testScr3, int testScr4, int testScr5);
int grades(int testScr1, int testScr2, int testScr3, int testScr4, int testScr5);
int main()
{
ifstream inFile;
inFile.open("grades.txt");
int lowest = 100;
int testScr1, testScr2, testScr3, testScr4, testScr5;


getScore(testScr1, inFile);
if (testScr1 < lowest)
{
    lowest = testScr1;
}
getScore(testScr2, inFile);
if (testScr2 < lowest)
{
    lowest = testScr2;
}
getScore(testScr3, inFile);
 if (testScr3 < lowest)
{
     lowest = testScr3;
}
getScore(testScr4, inFile);
 if (testScr4 < lowest)
{
    lowest = testScr4;
}
getScore(testScr5, inFile);
 if (testScr5 < lowest)
{
    lowest = testScr5;
}
calcAverage(testScr1, testScr2, testScr3, testScr4, testScr5);

inFile.close();

return lowest;
}

void getScore(int& score, ifstream& inFile)
{
inFile >> score;
}


void calcAverage(int testScr1, int testScr2, int testScr3, int testScr4, int testScr5)
{
int sum = 0;
int lowest;
double average;

lowest = findLowest(testScr1, testScr2, testScr3, testScr4, testScr5);

sum = testScr1 + testScr2 + testScr3 + testScr4 + testScr5 - lowest;
average = sum / 4.0;

cout << setw(4) << fixed << showpoint << setprecision(2);
cout << "The avergae of the four highest scores are: " << average << endl;
}

int findLowest(int testScr1, int testScr2, int testScr3, int testScr4, int testScr5)
{
int lowest = testScr1;

cout << "The lowest test score is: " << lowest << endl;

return lowest;
}