Code:
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;
//Project to input data on various fish
//including species, weight and length
//Determine ave weight, min & max length
//and number of fish per species
int FUNCaveweight(int Weight[100], string Species[100], string species);
int maxminLengths (int Length[100], string Species[100], string species);
int main (void)
{
//declare
int Length [100];
int Weight [100];
string Species [100];
string species;
int l=0, pounds, ounces, aveweight=0, totalweight=0, count=0, minLength=1000, maxLength=0;
//get input
// this goes on forever, since Length is just the ADDRESS of the memory location containing Length[0]
// did you really want this to run over & over again?
while (Length>=0)
{
// in the for loop you enter your data into the arrays; looks ok
for (l=0;l<100;l++)
{
cout<<"Enter species of fish, length in inches and weight in pounds and ounces:"<<endl;
cout<<"Enter -1 as length to end."<<endl;
cin>>Species[l]>>Length[l]>>pounds>>ounces;
Weight[l]=pounds*16+ounces;
}
// the first problem here is that Length and Species are not int variables, they are memory addresses
// but even after you fix that, what are you doing here? You're just calling the function over and
// over again, not doing anything at all with the values that the function is returning.
//max & min lengths
maxminLengths (Length, Species, "bass");
maxminLengths (Length, Species, "bluegill");
maxminLengths (Length, Species, "perch");
maxminLengths (Length, Species, "walleye");
maxminLengths (Length, Species, "pike");
// same problems here as in the preceding 5 lines
//aveweight
FUNCaveweight (Weight, Species, "bass");
FUNCaveweight (Weight, Species, "bluegill");
FUNCaveweight (Weight, Species, "perch");
FUNCaveweight (Weight, Species, "walleye");
FUNCaveweight (Weight, Species, "pike");
//format
cout.setf(ios::left);
cout.setf(ios::adjustfield);
// in main, totalweight=0, minLength=1000, maxLength=0; note that these variables in main
// are not affected by anything you do to variables with the same names in the other functions
//get returned info from functions
aveweight=totalweight/count;
cout<<species<<aveweight/16<<" lb "<<aveweight%16<<" ounces "<<minLength<<" in. to "<<maxLength<<" in. "<<count<<" fish"<<endl;
}
return EXIT_SUCCESS;
}
//function for aveweight
int FUNCaveweight(int Weight[100], string Species[100], string species)
{
int totalweight=0;
int t=0, count=0;
for (t=0;t<100;t++)
{
if (Species[t]==species)
totalweight+=Weight[t];
count++;
}
return totalweight/count;
}
//function for max and min lengths
int maxminLengths(int Length[100], string Species[100], string species)
{
int maxLength=0, minLength=1000, l=0;
for (l=0;l<100;l++)
{
if (Length[l]<maxLength)
maxLength=Length[l];
if (Length[l]>minLength)
minLength=Length[l];
if (maxLength==0)
maxLength=minLength;
}
return maxLength, minLength;
}