このプログラムは私にとって大きな頭痛の種でした。なんらかの理由で「生徒 3」に到達するとすぐにクラッシュします。スタックしている無限ループや、その時点でクラッシュするその他の理由が見つかりません。どんな助けでも大歓迎です。
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int ARRAY_SIZE = 5;
const int ARRAY_SIZE_TWO = 4;
const int ARRAY_SIZE_THREE = 20;
string names[ARRAY_SIZE];
double grades[ARRAY_SIZE];
double average[ARRAY_SIZE];
double averageFinal[ARRAY_SIZE];
string letter[ARRAY_SIZE] = {"A", "B", "C", "D", "F"};
string studentLetter[ARRAY_SIZE];
int counterOne = 0;
int counterTwo = 0;
int counterThree = 0;
double temp;
while (counterOne < ARRAY_SIZE)
{
system("CLS");
cout<<"Enter the name of student number " <<(counterOne + 1) <<":"<<endl;
cin>>names[counterOne];
while(counterTwo < ARRAY_SIZE_TWO)
{
system("CLS");
cout<<"Enter the test scores for " <<names[counterOne] <<":" <<endl;
cout<<"Enter test score number " <<(counterTwo + 1) <<" for " <<names[counterOne] <<":" <<endl;
cin>>grades[counterThree];
counterTwo += 1;
counterThree += 1;
average[counterOne] += grades[counterThree];
}
counterTwo = 0;
counterOne += 1;
}
counterOne = 0;
counterTwo = 0;
counterThree = 0;
while(counterOne < ARRAY_SIZE)
{
averageFinal[counterOne] = average[counterOne] / 12;
if (averageFinal[counterOne] < 89)
{
studentLetter[counterOne] = letter[0];
}
else if (averageFinal[counterOne] < 79)
{
studentLetter[counterOne] = letter[1];
}
else if (averageFinal[counterOne] < 69)
{
studentLetter[counterOne] = letter[2];
}
else if (averageFinal[counterOne] < 59)
{
studentLetter[counterOne] = letter[3];
}
else
{
studentLetter[counterOne] = letter[4];
}
counterOne += 1;
}
while(counterTwo < ARRAY_SIZE)
{
cout<<names[counterTwo] <<":" <<endl <<"Average: " <<averageFinal <<"%" <<endl <<"Letter Grade: " <<studentLetter[counterTwo] <<endl;
counterTwo += 1;
}
system("PAUSE");
return 0;
}