Code:
#include <stdio.h>
//prototypes
void greeting();
void readfile();
void displayResults(double avglength, double avgweight, double heaviest, double longest, int frequency, int heavyteam, int longteam);
void readfile(int team[], double length[], double weight[], int deadfish[]);
int main()
{
int team[70];
double length[70];
double weight[70];
int deadfish[70];
double sumlength = 0;
double sumweight = 0;
int frequency = 0;
double heaviest = 0;
double longest = 0;
double sum_weight_team[15];
int longteam;
int heavyteam;
greeting(); //calls method 'greeting'
int i;
int j;
for(i=0; i<70; i++)
{
team[i], length[i], weight[i], deadfish[i];
}
readfile(team, length, weight, deadfish);
for(i=0; i<70; i++)
{sumlength += length[i];} //Gets the sum of the length of all the fish.
double avglength = sumlength/70; //Gets the average length of all the fish.
for(i=0; i<70; i++)
{sumweight += weight[i];} //Gets the sum of the weight of all the fish.
double avgweight = sumweight/70; //Gets the average weight of all the fish.
for(i=0; i<70; i++)
{
if(deadfish[i] == 0) //Finds the number of dead fish (dead fish = 0).
{frequency++;}
}
for(i=0; i<70; i++)
{
if(weight[i]>heaviest) {heaviest=weight[i];
heavyteam = team[i]; }
}
for(i=0; i<70; i++)
{
if(length[i]>longest) {longest=length[i];
longteam = team[i]; }
}
for(j=0; j<70; j++)
{
sum_weight_team[team[j]] += weight[j];
}
for(j=1; j<16; j++)
{
if(j == 14) continue;
printf("The total weight of team %d is: %lf.\n", j, sum_weight_team[j]);
}
displayResults(avglength, avgweight, heaviest, longest, frequency, heavyteam, longteam);
return 0;
}
void greeting()
{
printf("\n");
}
void readfile(int team[], double length[], double weight[], int deadfish[])
{
FILE *infile = fopen("input.txt", "r");
if(infile !=NULL)
{
int i = 0;
while(fscanf(infile, "%d %lf %lf %d", &team[i], &length[i], &weight[i], &deadfish[i])!=EOF)
{
i++;
}
fclose(infile);
}
else {printf("The file was not opened successfully.\n");}
}
void displayResults(double avglength, double avgweight, double heaviest, double longest, int frequency, int heavyteam, int longteam)
{
printf("The average length overall of all the fish is %.4lf and the average weight overall is %.4lf.\n", avglength, avgweight);
printf("The number of dead fish overall is %d.\n", frequency);
printf("The heaviest fish is %lf caught by team %d.\n", heaviest, heavyteam);
printf("The longest is %lf caught by team %d.\n", longest, longteam);
}