All the program does is calculate up to 30 "students" gpa and prints the average of them whenever the user presses zero. Here's an output of it:

Notice how the result is soo big?What's wrong with it? Here is my code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
float x, gpa[30], avg;
int i = 0, j;
printf("\n[GPA Calculator]\n\n");
do {
printf("Please enter a GPA score.\n To stop entering values and calculate the current GPA average, Enter 0.\n You are entering score # %d.\n", i + 1);
scanf("%f", &x);
if(x != 0) {
gpa[i] = x;
i++;
}
else {
for(j = 0; j < i; j++) {
avg += gpa[i];
avg = avg / i;
}
printf("The average GPA of the %d Entered Scores is: %f. Program exited.\n", i, avg);
break;
}
if(i == 29) {
for(j = 0; j < i; j++) {
avg += gpa[i];
avg = avg / i;
}
printf("The average GPA of the %d entered scores is %f. Program exited.\n", i, avg);
break;
}
} while (i < 30);
return 0;
}


Sign In
Create Account


Back to top









