-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPA calculator.cpp
96 lines (65 loc) · 2.24 KB
/
GPA calculator.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
using namespace std;
//this function sums the values in array
int sumGradePoint(double gradePoint[], int numOfCourses){
{
double sum = 0;
for(int j = 0; j < numOfCourses; j++)
sum += gradePoint[j];
return sum;
}
}
int main()
{
int numOfCourses;
int creditHours;
cout << "Enter number of courses: ";
cin >> numOfCourses;
cout << endl;
cout << "Enter credit hours: ";
cin >> creditHours;
cout << endl;
double gradePoint[numOfCourses - 1];
//gradepoints collected into array
for(int i = 0; i < numOfCourses; i++){
cout << "Enter grade point: ";
cin >> gradePoint[i];
}
double sumOfGrade = sumGradePoint(gradePoint, numOfCourses);
double gpa = sumOfGrade / (numOfCourses * creditHours);
cout << "\nYour GPA is: " << gpa;
if (gpa >= 3.6 && gpa <= 4.0){ //gpa classification
cout << "\n\nFirst Class\n\n";
}else if(gpa >= 3.0 && gpa <= 3.599){
cout << "\n\nSecond Class (Upper Division)\n\n";
}else if(gpa >= 2.00 && gpa <= 2.999){
cout << "\n\nSecond Class (Lower Division)\n\n";
}else if(gpa >= 1.50 && gpa <= 1.999){
cout << "\n\nThird Class\n\n";
}else if(gpa >= 1.00 && gpa <= 1.499){
cout << "\n\nPass\n\n";
}else if(gpa >= 0.00 && gpa <= 0.999){
cout << "\n\nFail\n\n";
}else{
cout << "\n\nYou might have made a wrong input\n\n";
}
cout << "Your performance chart is shown below: \n\n";
//Performance chart
int j = 0;
while((int)(gradePoint[j]) != 0){ /*casting grades with decimal points to int*/
gradePoint[j] -= 1;
cout << "[#";
if((int)(gradePoint[j]) == 0){
cout << endl;
j++;
}else if(j == numOfCourses - 1){
while((int)(gradePoint[j]) != 0){
gradePoint[j] -= 1;
cout << "[#";
}
break;
}
}
cout << endl << endl;
return 0;
}