Program is designed to return the average of a series of 7 scores, with the max and min removed, a la judging in ice skating.
I'm getting no return, with a printf check before any code not returning.
Any help is greatly appreciated.
Code:
/*Brendan Keeler - Oct. 5, 2009 - The purpose of this program is to read from the file in an array, compute maximum, minimum, average, and return average from function to main and then printing average.*/
#include <stdio.h>
void read_file(int (*scores)[7]){
FILE *fin;
int i=0;
fin = fopen("input.txt", "r");
while(!feof(fin)) {
/* loop through and store the numbers into the array */
fscanf(fin, "%d", scores[i]);
i++;
}
fclose(fin);
}
int compute(int (*scores)[7]){
int i = 0;
int total=0, average, max=*scores[1], min=*scores[1];
for(i = 0; i<7; i++){
total = total + *scores[i];
if (*scores[i] > max){
max = *scores[i];
}
if (*scores[i] < min){
min = *scores[i];
total = total - max - min;
}
}
average = total/7;
return average;
}
void show_average(average){
printf("The average of the scores, when the max and min are removed is %d", average);
}
main(){
int numbers[7], average;
read_file(&numbers);
int mean;
average = compute(&numbers);
show_average(mean);
}