GPA calculator bug

Hello, programmers, I am a noob in programming and was told that to learn more, I need to do some project and so I started this GPA calculator that eventually prints your GPS in both 5unit and it 4 unit equivalent. The problem is I created an array to hold the grade point from A-F and another array to hold the letter grade from 0-5, but after I was done it performed well until I noticed it crashes when I try to calculate for more than 6 courses, I have tried what I can do but still can't detect the bug.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#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 corredponds 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] = "grin";
			}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;

}
gradePoint and letterGrade are arrays of 6 elements each. With numOfCourse equal to 7, for example, it triggers out of bounds access inside the for loop (line 31 and below)
Topic archived. No new replies allowed.