我將main方法與main方法分開,兩位同學都在調用方法,但我不太確定如何通過這種方式計算平均值,有什麼想法?以另一種方法計算平均值C++
平均做兩件事。它計算學生分數的平均值,將整數平均值放入最終元素中,從而替換負數,然後返回它在數組中找到的實際測試分數。數組中的哨兵是負數。
這裏是我的代碼
#include <iostream>
using namespace std;
double average(int array[]); // function declaration (prototype)
int main()
{
int lazlo[] = {90, 80, 85, 75, 65, -10};
int pietra[] = { 100, 89, 83, 96, 98, 72, 78, -1};
int num;
num = average(lazlo);
cout << "lazlo took " << num << "tests. Average: " << lazlo[ num ] << endl;
num = average(pietra);
cout << "pietra took " << num << "test. Average: " << pietra[ num ] << endl;
}
double average(int array[])
{
// Average code
}
你'average'功能已經不知道有多少項目有在數組中。這有助於你找出遺漏的東西嗎? – PaulMcKenzie