# Pulling numbers from a .txt file and displaying certain things (averages, etc.)

This is a discussion on Pulling numbers from a .txt file and displaying certain things (averages, etc.) within the C Programming forums, part of the General Programming Boards category; Hello. I'm gonna try and explain this the best I can. Pretty much I'm working on something that simulates a ...

1. ## Pulling numbers from a .txt file and displaying certain things (averages, etc.)

Hello. I'm gonna try and explain this the best I can. Pretty much I'm working on something that simulates a fishing tournament. I made a .txt file with four columns. Column 1 is team number, column 2 is length, column 3 is weight, and column 4 is number of dead fish.

There's 70 fish total, 5 per team, and there are 14 teams (although the last team is called team "15", I just skipped 14 for some reason, will fix it later).

The part I'm having issues with is that I want to find the total weight of fish for EACH team. Should I do a for loop, and then do something like
Code:
`if(team[i]=1) {sumweight +- weight[i]}`
??

Here's the code (ignore the empty functions):
Code:
```#include <stdio.h>

//prototypes
void greeting();
void displayResults(int team, double length, double weight, int deadfish);

int main()
{
int team[70];
double length[70];
double weight[70];
double sumlength = 0;
double sumweight = 0;
int frequency = 0;
double heaviest = 0;
double longest = 0;

greeting();
int i;

for(i=0; i<70; i++)
{
scanf("%d %lf %lf %d", &team[i], &length[i], &weight[i], &deadfish[i]); //Reads the values in the redirected file.
}

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++)
{
{frequency++;}
}

for(i=0; i<70; i++)
{
if(weight[i]>heaviest) {heaviest=weight[i];}
}

for(i=0; i<70; i++)
{
if(length[i]>longest) {longest=length[i];}
}

printf("The average length overall of all the fish is %lf and the average weight overall is %lf.\n", avglength, avgweight);
printf("The number of dead fish overall is %d.\n", frequency);
printf("The heaviest fish is %lf and the longest is %lf.\n", heaviest, longest);
}

void greeting()
{
printf("");
}

`sumweight[team[i]] += weight[i];`