| | |
Homework - Array/Functions
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 17
Reputation:
Solved Threads: 0
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.
Any help would be appreciate it. Thank you.
C++ Syntax (Toggle Plain Text)
#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; } }
•
•
Join Date: Oct 2008
Posts: 17
Reputation:
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?
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?
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
•
•
•
•
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?
![]() |
Similar Threads
- circular array + queue (C++)
- Sorting 2d Array (C)
- C++ Homework #1 (C++)
- Trying to write information in a text file -> Array (Java)
- Homework Help (Java)
- Homework Help. (C++)
- Country code conversion (PHP)
- Dynamic memory allocation homework (C++)
Other Threads in the C++ Forum
- Previous Thread: Generate 6 Random Numbers
- Next Thread: Real time clock
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






