954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Homework - Array/Functions

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;
          }
     }
StainlessSteelR
Newbie Poster
17 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

int max_id = -1;
for (int i=0; imax) {
max=fish[i];
max_id = i;
}

}
cout<<"The maxmum number of fish caught was " <

james_zheng
Newbie Poster
15 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

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.

StainlessSteelR
Newbie Poster
17 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

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

james_zheng
Newbie Poster
15 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

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?

StainlessSteelR
Newbie Poster
17 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 
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.

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You