View Single Post
Join Date: Jul 2005
Posts: 1,760
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 283
Lerner Lerner is online now Online
Posting Virtuoso

Re: Logic error, simple stat prog

 
0
  #8
Dec 1st, 2008
In getlargest() count will act as the index of the element with the largest rainfall for that year. Since count is passed to getlargest() by reference you don't need to return anything if there are no other requirements of the function. Use some counter variable other than count to control the loop and keep track of count separately.
  1. void getLargest(double array[], int size, int &count)
  2. {
  3. count = 0; //assume first element is largest
  4.  
  5. for (int i = 1; i < size; i++)
  6. {
  7. if (array[i] > array[count])
  8. {
  9. count = i;
  10. }
  11. }
  12. }
and back in main() use count to display the result;
cout << "the largerst rainfall was " << array[count];
Klatu Barada Nikto
Reply With Quote