これは私の教科書の点数計算の練習問題です。7 つのスコアを取り、最高点と最低点を落とします。
構文エラーはないと思いますが、未解決の外部シンボル エラーが発生しています。私は同様の質問を探しましたが、問題は関数を使用しているが定義していないことにあるようです。私はすべての関数を定義しましたが、おそらく main または calculatecore のいずれかで間違っています。私は c++ を初めて使用するので、この問題を解決するための支援をいただければ幸いです。ありがとうございました
これは、VisualStudio で発生したエラーです。
エラー LNK2019: 未解決の外部シンボル "float __cdecl calculateScore(float * const,int,float)" (?calculateScore@@YAMQAMHM@Z) が関数 _main で参照されています
#include <iostream>
using namespace std;
void printHeader(int judges);
void enterData (float scores[], int judges, float difficulty);
float calculateScore(float scores[], const int judges, float difficulty);
int findLeast(float scores[], const int judges);
int findMax(float scores[], const int judges);
int main () {
const int judges = 7;
float scores [judges];
float difficulty = 0;
float finalscore = calculateScore(scores, judges, difficulty);
printHeader (judges);
enterData (scores, judges, difficulty); // get user input
findLeast(scores, judges); // find lowest score
findMax(scores, judges); // find highest score
calculateScore (scores, judges, difficulty); // get final score
cout << "The final score is " << finalscore << '\n';
return 0;
}
void printHeader(const int judges) {
cout << "This program calculates a divers score over" << judges << "judges";
}
void enterData(float scores[], const int judges, float difficulty) {
for (int i = 0; i < judges; i++){
cout <<"Enter score for judge " << i+1 << endl;
cin >> scores[i];
}
cout << "Enter difficulty: "<< endl;
cin >> difficulty;
}
これは、メインで呼び出されるスコアを計算するための私の関数です。代わりにvoid関数にする必要がありますか?
float calculateScore(float scores[], const int judges, float difficulty, int maxScore, int least) {
float sum = 0;
for (int i = 0; i < judges; i++) {
sum += scores[i];
}
return sum - scores[least] - scores[maxScore] * difficulty * .6;
}
int findLeast(float scores[], const int judges) {
int least = 0;
for (int i = 1; i< judges; i++)
if (scores[i] < scores[least])
least = i;
return least;
}
int findMax(float scores[], const int judges) {
int maxScore = 0;
for (int i = 1; i< judges; i++)
if (scores[i] > scores[maxScore]) {
maxScore = i;
}
return maxScore;
}