I'm learning C programming and I've encountered a problem using scanf for initializing values into the array. In this example, 10, 32 and 20 were input as values for the array; 20 should be in grades[2] but its value is 0.
Why doesn't the program register the last value that is input?
That is the relevant code.
I'll appreciate any help in understanding what went wrong with the program.
#include <math.h>
#include <stdio.h>
#include <stdbool.h>
#define N 50
#define MaximalSTD 10
int main() {
printf("Please enter the grades of the examinees");
printf(" followed by the expected mean\n");
double grades[N], ReqMean;
int numgrade = 0;
for (int i = 0; i < N; i++) {
if (scanf("%lf", &grades[i]) == 1) {
numgrade++;
} else
break;
}
ReqMean = grades[numgrade - 1];
printf("numgrade: %d\nReqMean: %d\n", numgrade, ReqMean);
return 0;
}