# Thread: Stuck on this kinda long code

1. ## Stuck on this kinda long code

Hello. I've been working on this code that simulates a fishing tournament. There's 14 teams (although there is no "team 14", goes from team 13 to team 15), each team picks 5 fish, and the program reads in the team number, the length, weight, and if the fish is dead or alive for each fish. I figured out a lot of stuff, like the total weight of each team, etc. However, I'm having problems on two things, and that is the penalties I need to calculate in. Here they are:

• 1 Dead = 0.25 lbs
• 2 Dead = .625 lbs
• 3 Dead = 1.125 lbs
• 4 Dead = 1.75 lbs
• 5 Dead = 2.5 lbs

Length Penalty
• 1 lb subtracted for each fish under minimum length
• Minimum length is 7 inches

I'm guessing I should've figured out the penalties before I calculated all the weights, because now I'm just confused on where to even begin. I need to subtract the weight penalties from all the weight calculations. Anyways, here's my code, any help would be greatly appreciated!

Code:
```#include <stdio.h>

//prototypes
void greeting();
void displayResults(double avglength, double avgweight, double heaviest, double longest, int frequency, int heavyteam, int longteam);

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;
double sum_weight_team[15];
int longteam;
int heavyteam;

greeting(); //calls method 'greeting'

int i;
int j;

for(i=0; i<70; i++)
{
}

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];
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");
}

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

2. Code:
```
double sum_weight_team[15];
...
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]);
}
```

See a problem?

It's a bad idea to code your array sizes everywhere. Not only are you prone to error, but what if your boss tells you the arrays need to be twice the size due to a design change? That's a lot of hunting and editing. Use define for array dimensions.

3. Ohhhhhhh alright. Yeah I see. I figured it out. Thank you for the tip!