1
我最近試圖制定一個計劃,它可以計算所有考試成績的最高考試成績,最低考試成績和平均成績。最高和最低的平均C++
到目前爲止,我的程序已經能夠做到這一點;然後,我試着看看能不能計算出所有平均值的最高值,以及所有平均值的最低值,而我無法弄清楚。
我已經嘗試了很多東西,迄今爲止沒有任何工作。現在我所獲得的全部測試分數,平均分,最高測試分數和最低分,但不是平均分中的最高和最低分。我能做些什麼來更好地理解這一點?
任何提示,建議非常感謝。我將闡述我到目前爲止所做的工作。
#include <iostream>
#include <iomanip>
using namespace std;
const int amount = 3;
int count;
int Total = 0;
int TestScore1[amount], TestScore2 [amount], TestScore3 [amount];
double average[amount];
int main()
{
for(int count = 0; count < amount; count++)
{
cout<<"Enter Test Score " << (count + 1) << ": " <<endl;
cin>> TestScore1[count];
cin>>TestScore2[count];
cin>>TestScore3[count];
}
cout<<"Your test result are: \n Test 1: Test 2: Test 3: Average: "<<endl;
for(int count = 0; count < amount; count++)
{
Total = 0;
double average = 0;
Total += TestScore1[count];
Total += TestScore2[count];
Total += TestScore3[count];
average = Total/amount;
cout << " " << TestScore1[count]
<< " \t" << TestScore2[count]
<<" \t "<< TestScore3[count] <<"\t" << average <<endl;
}
double highest = TestScore1[0];
for(int count = 1; count < amount; count++)
{
if(TestScore1[count] > highest)
highest = TestScore1[count];
}
cout<<"Test 1 Highest: " <<highest <<endl;
double highest2 = TestScore2[0];
for(int count = 1; count < amount; count++)
{
if(TestScore2[count] > highest)
highest2 = TestScore2[count];
}
cout<<"Test 2 Highest: " <<highest2 <<endl;
double highest3 = TestScore3[0];
for(int count = 1; count < amount; count++)
{
if(TestScore3[count] > highest)
highest3 = TestScore3[count];
}
cout<<"Test 3 Highest: " <<highest3 <<endl;
double Lowest = TestScore1[0];
for(int count = 1; count < amount; count++)
{
if(TestScore1[count] < Lowest)
Lowest = TestScore1[count];
}
cout<<"Test 1 Lowest: " <<Lowest <<endl;
double Lowest2 = TestScore2[0];
for(int count = 1; count < amount; count++)
{
if(TestScore2[count] < Lowest2)
Lowest2 = TestScore2[count];
}
cout<<"Test 2 Lowest: " <<Lowest2 <<endl;
double Lowest3 = TestScore3[0];
for(int count = 1; count < amount; count++)
{
if(TestScore3[count] < Lowest3)
Lowest3 = TestScore3[count];
}
cout<<"Test 3 Lowest: " <<Lowest3 <<endl;
}
'double average = 0;'在你的循環中「隱藏」上面的平均聲明數組。所以,你永遠不會在該循環之外存儲平均值。 – Chad
雖然在一個循環中隱藏數組名稱的標量爲「double average」,但似乎並沒有寫入「average [count]」。如果您沒有編寫任何代碼來完成這項工作,您希望在哪裏填充平均數組? – Useless
@chad你是對的。這工作。謝謝。 – ReMaKe