944,201 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5861
  • C++ RSS
May 14th, 2006
0

help with finding minimum value

Expand Post »
need help in findin the minimum of these 5 inputs
its keeps showin 2 instead of 1...

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int findMin(int [], int);
  6.  
  7. int main()
  8. {
  9. const int MAXELS= 5;
  10. int nums[MAXELS] = {2, 18, 1, 27, 16};
  11.  
  12. cout << "The minimum value is " << findMin(nums, MAXELS) << endl;
  13.  
  14. system("pause");
  15. return 0;
  16. }
  17.  
  18. // find the minimum value
  19. int findMin(int vals[], int MAXELS)
  20. {
  21. int i, min = vals[0];
  22.  
  23. for (i = 1; i >= MAXELS; i++)
  24. if (min >= vals[i])
  25. min = vals[i];
  26.  
  27. return min;
  28. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vietbong87 is offline Offline
11 posts
since Apr 2006
May 14th, 2006
0

Re: help with finding minimum value

    for (i = 0; i < MAXELS; i++)
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
May 14th, 2006
0

Re: help with finding minimum value

thanks heaps ur a champ!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vietbong87 is offline Offline
11 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: converting std::string to const chars?
Next Thread in C++ Forum Timeline: what is error with this ...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC