代码运行良好,只是它不会降低最低分数然后计算它。
输出示例:
您想输入多少个考试成绩?
3
输入所需的测试分数:
分数 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;
}