I'm having some problems with a program that invovles arrays. I have a program that is suppose to read data from a file fish.txt about fisherman. The a function is suppose to print the number of fish that need to be thrown back because their is a maximum of 14 fish allowed. Then finally I need a function that is suppose to print the fisherman number with the most fish and how many they caught. Something is wrong with the math for the number of maximum fish and a problem with the fisherman who caught the most it goes through each one which and doesn't display their array number.
Any help would be appreciate it. Thank you.

#include <iostream>
#include <iomanip>
using namespace std;

void getData (int[]);
void throwback (int [], int);
void findMax (int[], int);

int main()
{
const int NUM_FISH=20;
int fish[NUM_FISH];
int badfish;
int max;

// print fish data
   cout << "Fish Story Data\n"
        << "---------------\n";
for (int i=0; i < NUM_FISH; i++ )
    {
     cout << setw(2) << i << setw(6) << fish[i] << endl;
     }
// read fish data

getData (fish);
throwback (fish, badfish);
findMax (fish, max);


return 0;
}

void getData (int fish [])
     {
int NUM_FISH = 20;
for (int i=0; i < NUM_FISH; i++ )
          {
//   cout << "enter number of fish caught by person: " << i << "  ";
      cin >> fish[i];
           }
      }

void throwback (int fish [],int badfish)
      {
int goodfish = 14;
int NUM_FISH = 20;
      for (int i=0; i < NUM_FISH; i++ )
           {
           if(fish[i]>goodfish)
           badfish=fish[i]-goodfish;
          }
      }

void findMax (int fish [], int max)
     {
int NUM_FISH = 20;
max = 0;
     for (int i=0; i<NUM_FISH; i++)
          {
          if (fish[i]>max)
          max=fish[i];
          cout<<"The maxmum number of fish caught was " <<max <<"by "
<<fish[i]<<endl;
          }
     }
int max_id = -1;   
for (int i=0; i<NUM_FISH; i++)
          {
          if (fish[i]>max) {
              max=fish[i];
              max_id = i;
          }

          }
 cout<<"The maxmum number of fish caught was " <<max <<"by "
<<max_id<<endl;

I need a function and that code produced alot of errors when I tried to make it a function or add it into the main.

just simply modify your findMax function to the code i gave you.

Okay I got it to work halfway. I had to put the cout statement inside the last } because of an "error: expected constructor, destructor, or type conversion before '<<' token". Don't know what that means....
Theirs just one problem with the findMax function the max_id= i; produces the last array number not the array number that corresponds with the maximum number of fish. That doesn't max since to me because it shouldn't enter the for loop correct?

Okay I got it to work halfway. I had to put the cout statement inside the last } because of an "error: expected constructor, destructor, or type conversion before '<<' token". Don't know what that means....
Theirs just one problem with the findMax function the max_id= i; produces the last array number not the array number that corresponds with the maximum number of fish. That doesn't max since to me because it shouldn't enter the for loop correct?

Post your updated code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.