代碼運行良好,除非它不降低最低分並計算它。程序不會降低最低分,並計算沒有它的平均分
輸出例:
多少測試成績你想進入?
進入測試得分期望:
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