1) I have an issue with the loop that I have set in order to read how many subjects the user wants to key in.
Already answered by @Nishan in a comment. Just replace for (int i=1;i >= subjects; i++)
by for (int i=1;i <= subjects; i++)
.
2) When I tried to print "Grade = " + subjectGrade); my compiler says it hasn't been initialized. Same goes to the GradePoint and subjectCreditHour.
Already answered.
3) And I couldn't figure out how to get the program to calculate the Total Subject Grade Points, Total Credit Hours, and CGPA. Because depending on how many numbers of subjects the user wants, I can't figure out how to get the program to take in the user's input and sum them up together
You already are on the right way since you have the accumulators you need:
double subjectGradePoint = 0d;
double CGPA = 0d;
double totalSubjectGP = 0d;
int totalCreditHour = 0;
Whitin your loop and after nested if-else
blocks, you need to update subjectGradePoint
, totalSubjectGP
and totalCreditHour
variables in each iteration:
subjectGradePoint = GradePoint * CreditHour;
totalSubjectGP += subjectGradePoint;
totalCreditHour += CreditHour;
Finally, after your loop calculate CGPA
:
CGPA = totalSubjectGP / totalCreditHour;