![]() |
| ||
| 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> |
| ||
| Re: Homework - Array/Functions 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; |
| ||
| Re: Homework - Array/Functions 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. |
| ||
| Re: Homework - Array/Functions just simply modify your findMax function to the code i gave you. |
| ||
| Re: Homework - Array/Functions 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? |
| ||
| Re: Homework - Array/Functions Quote:
|
| All times are GMT -4. The time now is 6:29 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC