I have a logic error in this code. I believe it is in the last two blocks of code. I keep getting the same output regardless of the values I put in.
Code:
/* scores.c >>>>> using loops to process arrays */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
int main(void)
{
int index, score[SIZE];
int sum = 0;
float average;
printf("Enter %d scores:\n", SIZE);
for (index = 0; index < SIZE; index++)
scanf("%d", &score[index]); /* accepts ten scores regardless of whitespace */
printf("The scores read in are as follows:\n");
for (index = 0; index < SIZE; index++);
printf("%5d", score[index]);
printf("\n");
for (index = 0; index < SIZE; index++);
sum += score[index];
average = (float) sum/SIZE;
printf("Sum of scores = %d, average = %.2f\n", sum, average);
system("pause");
return (0);
}
This is always the output.
Code:
Enter 10 scores:
10
10
10
10
10
10
101
10
10
10
The scores read in are as follows:
37814124
Sum of scores = 37814124, average = 3781412.50
Press any key to continue . . .