I have posted before on this forum in this thread. This is basically a follow-up, but the old thread is not needed, because this is an isolated problom.
This is what I got now to extract the lowest and highest score of an 5 x 5 array.
Code:
/* initialised the values to compute the highest and lowest score */
int low_score = 11;
int high_score = -1;
for(j = 0; j < NR_QUIZES ; j++) {
total_score=0; /*reset total score for quizes */
for(i = 0; i < NR_STUDENTS ; i++) { {
total_score += score[i][j];
}
/* Here is the highest and lowest score computed using 2 if statements */
if(score[i][j] < low_score) { /* if the grade is lower than 11, then the low_score gets updated */
low_score = score[i][j];
}
if(score[i][j] > high_score) { /* if the grade is higher than -1, then the high_score gets updated */
high_score = score[i][j];
}
}
printf("\nQuiz %d: Lowest score = %d, Highest score = %d, Average score = %.1f", j+1, low_score, high_score,(float)total_score/NR_STUDENTS);
}
It works for quiz 1, but it won't work for quiz 2 to 5. It keeps the highest score from quiz 1 for quiz 2 to 5. The lowest score from quiz 2 is used for quiz 2 to 5 also. I think the code is right, but I need to add more code probably to reset the highest and lowest score after each quiz. Right? (This is what I'm logically thinking).
I think it can be done by naming
Code:
high_score=o;
low_score=o;
I have tried it several times, but it won't work. Tips appreciated.