今日の私の問題はダイナミックアレイの問題です。 "* ./a.outのエラー:ダブルフリーまたは破損(アウト):0x09c2e028 * 中止されました(エラーが発生しました)コアダンプされた) "私は配列に何か間違っていますか?それとも私は痛いほど逃げているものがありますか?ダブルフリーまたはダイナミックアレイの破損
プログラムは、無制限のテストスコアとそれぞれの可能な最大ポイント(つまり、テストスコア= 76最大テストスコア= 100)をとり、それらの数値をGPAに変換することになっています。私は、GPAを作成するために使用しているクラスのみを含んでいます。これは、コードの残りの部分がまだ完成していないためです。
私は動的割り当てを使用する必要があります。なぜなら、それは学校の割り当てのためです。
読んでいただきありがとうございます。誰かが私を助けることを願っています!
#include <iostream>
#include <string>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <cassert>
using namespace std;
void programGreeting();
class testScores{
public:
float testAverage(){
int i = 0;
float gpa2 = 0;
int loopCountVar = 0;
int size = 1;
int size2 = 1;
float *testScore = new float[size];
float *maxScore = new float[size];
while(testScore[i] != -1){
i++;
loopCountVar++;
cout << "Enter test score #" << loopCountVar << endl;
cin >> testScore[i];
if(testScore[i] == -1){
size = i;
}
assert(testScore[i] > -2);
cout << "Enter max test score #" << loopCountVar << endl;
cin >> maxScore[i];
if(maxScore[i] == -1){
size2 = i;
}
assert(maxScore[i] > -2);
}
float *gpa = new float[size];
for(i = 1; i < size; i++){
gpa[i] = testScore[i]/maxScore[i];
cout << gpa[i] << " " << endl;
}
for(i = 1; i < size; i++){
gpa2 += gpa[i];
}
for (i = 1; i < size; i++){
cout << endl << testScore[i] << " " << endl;
}
for (i = 1; i < size2; i++){
cout << endl << maxScore[i] << " ";
}
cout << endl << gpa2 << endl;
cin >> size;
delete testScore;
delete [] maxScore;
delete gpa;
return 0;
}
};