Hi guys, i'm having a little trouble getting my GPA average calculator to work as one of the challenges from the book. The sample data is:
GPA = 3.5, 2.8, 3.0, 2.5, 4.0, 3.7
avg GPA = 3.25
i can't seem to get the sample data above to work. For me i think there something wrong with the data types. Shouldn't i be using float for decimal type values? Correct me if i'm wrong.
Code:
#include <stdio.h>
float iGPA[29];
int main(void) {
int x;
float countGPA = 0;
int iSelection;
float eGPA;
float gpaTOTAL;
float avgGPA = 0;;
printf("\n\tGPA Average Calculator\n");
for (x = 0; x < 29; x++) {
printf("\nEnter gpa: ");
scanf("%f", &eGPA);
iGPA[x] = eGPA;
countGPA++;
printf("\n1\tAdd GPA: \n");
printf("2\tCalculate average GPA: ");
printf("\nEnter selection: ");
scanf("%d", &iSelection);
if (iSelection == 2) {
break;
}
}
int y;
for (y = 0; y < countGPA; y++) {
gpaTOTAL = iGPA[y];
gpaTOTAL += gpaTOTAL;
}
avgGPA = gpaTOTAL / countGPA;
printf("\nAverage GPA is: %f", avgGPA);
}