代码运行良好,除非它不降低最低分并计算它。程序不会降低最低分,并计算没有它的平均分
输出例:
多少测试成绩你想进入?
进入测试得分期望:
1分:58
评分2:96
3分:78
测试分数平均具有最低下降是:116.00
问题: 正如你可以在输出示例中看到,这是不正确的。它必须显示不包括最低的平均值。您可以查看我的代码并让我知道我哪里出错了吗?我也有几个人也看过它,他们无法看到我的代码中有任何错误。下面是我的代码:
代码:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//To dynamically allocate an array, Accumulator, to hold the average scores.
double *score;
double total = 0;
double average;
//int for counter, to hold the number of test scores.
int count;
int numTest;
// To obtain the number of test scores the user would like to enter.
cout << "How many test scores would you like to enter? " << endl;
cin >> numTest;
//Dynamically allocates an array large enough to hold the amount of test scores to enter.
score = new double[numTest];
//Get the test scores.
cout << "Enter the test score desired. " << endl;
for (count = 0; count < numTest; count++)
{
cout << "Score " << (count + 1) << ": ";
cin >> score[count];
}
//Find lowest score.
int lowest = score[count];
for (count = 1; count < numTest; count++)
{
if (score[count] < lowest)
lowest = score[0];
}
//Calculate the total test scores.
for (count = 0; count < numTest; count++)
{
total += score[count];
total -= lowest;
}
//Calculate the test scores average minus the lowest score.
average = total/(numTest - 1);
//Display the results
cout << fixed << showpoint << setprecision(2);
cout << "Test Scores Average with the lowest dropped is: " << average << endl;
//Free dynamically allocated memory
delete [] score;
score = 0; // Makes score point to null.
system("pause");
return 0;
}
'新的双[numTest]' - 好恶。试试'std :: vector'。 –
逐步查找找到最低分数的代码。 –
'std :: min_element' – chris