我是编程中的菜鸟,并被告知要了解更多,我需要做一些项目,所以我开始使用这个GPA计算器,最终以5个单位和4个单位相当于打印你的GPS。
问题是我创建了一个数组来保持AF的等级点和另一个数组来保持0-5的字母等级,但是在我完成之后它表现很好,直到我注意到它在我尝试计算更多时崩溃比起6门课程,我已经尝试了我能做的但仍然无法检测到这个问题并解决问题都无济于事。
#include<iomanip>
#include <iostream>
using namespace std;
int main(){
int numOfCourse;
cout<<"insert the number of courses offered: ";
cin>>numOfCourse;
int scores[numOfCourse];//an array that stores the number of course inputed by the user
int creditUnit[numOfCourse];//another array that stores the credit unit of the user
int qualityPoint[numOfCourse];//this is gotten by multiplying the credit unit by grade point
int totalQualityPoint=0;
int totalCreditUnit=0;
int gradePoint[6];//predefined grade point 0-5
string letterGrade[6];//predefined letter grade A-F which corresponds with the grade point
float gradePointAverage5;//5 point GPA Scale
float gradePointAverage4;// 4 point GPA Scale
// Asks the user to input scores and credit load of the courses
for (int i=0; i< numOfCourse; i++){
cout<<"input the scores of the course: ";
cin>>scores[i];
cout<<" input the credit load of the course: ";
cin>>creditUnit[i];
//defining the gradepoint and its corresponding letter grade
if(scores[i] <= 39){
gradePoint[i]=0;
letterGrade[i] = "F";
} else if (scores[i] >=40 && scores[i] <= 44){
gradePoint[i]=1;
letterGrade[i] ="E";
} else if (scores[i] >=45 &&scores[i]<= 49){
gradePoint[i]=2;
letterGrade[i] = "D";
}else if (scores[i] >=50 &&scores[i] <= 59){
gradePoint[i] =3;
letterGrade[i] = "C";
}else if (scores[i] >=60 &&scores[i] <= 69){
gradePoint[i]=4;
letterGrade[i] = "B";
}else if (scores[i]>=69 &&scores[i] <= 100){
gradePoint[i]=5;
letterGrade[i] = "A";
}else{
cout<< "Your grade is incorrect"<<endl;
return 0;
}
}
cout<<"Scores Letter Credit Grade QualityPoint"<<endl;
cout<<" Grade Unit Point (CU * GP)"<<endl;
for(int i =0; i<numOfCourse;i++){
qualityPoint[i] = creditUnit[i] * gradePoint[i];
cout<<scores[i] <<" "<<letterGrade[i]<<" "<<creditUnit[i]
<<" "<<gradePoint[i]<< " "<<qualityPoint[i]<<endl;
totalQualityPoint=totalQualityPoint + qualityPoint[i];
totalCreditUnit=totalCreditUnit + creditUnit[i];
gradePointAverage5= float(totalQualityPoint)/float(totalCreditUnit);
gradePointAverage4 = (gradePointAverage5/5)*4;
}
cout<< "Your total Quality Point is: "<<totalQualityPoint<<endl;
cout<< "Your total Credit Unit is: "<<totalCreditUnit<<endl;
cout<< "Your Grade Point Average (GPA) on the 5 point scale is : "<<setprecision(2)<<fixed<<gradePointAverage5<<endl;
cout<< "Your Grade Point Average (GPA) on the 4 point scale is : "<<setprecision(2)<<fixed<<gradePointAverage4<<endl;
}