私のコードで助けが必要です...何が間違っているのか、どうやって修正するのか分かりません。私はそれが私の変数と参照を宣言して何かを持っていると思うが、私はバグを修正する方法を完全にはわかっていない。助けてください!C++の平均と分散を計算する
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double calculate_average(int test_values[], int& size, int& sum, double& average) {
int i;
for (i = 0; i < size; i++) {
sum += test_values[i];
};
return average = sum/i;
};
double var(int test_values[], int size, double average, double& variance) {
for (int j = 0; j < size; j++) {
variance += pow((test_values[j] - average), 2);
};
return variance;
};
int main() {
int test_values[] = { 89, 95, 72, 83, 99, 54, 86, 75, 92, 73, 79, 75, 82, 53 };
int size = sizeof(test_values);
int sum;
double average, variance;
int calculate_average(int test_values[], int size, int sum, double average);
int var(int test_values[], int size, double average, double variance);
cout << fixed << showpoint << setprecision(2);
cout << test_values << endl;
cout << average << endl;
cout << variance << endl;
return 0;
}
私が与えることができる最も良いアドバイスは、デバッガで行ごとにコードを検査し、変数値が実際にどのように変化しているかを監視することです。 –
「何が間違っているのかわからない」というのは、役に立つ問題の説明ではありません。少なくとも、あなたはそれが間違っていると信じている理由を説明することができます。 –
は出力を期待していますか?実際の出力? – ggrr