help with finding minimum value

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2006
Posts: 11
Reputation: vietbong87 is an unknown quantity at this point 
Solved Threads: 0
vietbong87 vietbong87 is offline Offline
Newbie Poster

help with finding minimum value

 
0
  #1
May 14th, 2006
need help in findin the minimum of these 5 inputs
its keeps showin 2 instead of 1...

  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. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,362
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: help with finding minimum value

 
0
  #2
May 14th, 2006
    for (i = 0; i < MAXELS; i++)
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 11
Reputation: vietbong87 is an unknown quantity at this point 
Solved Threads: 0
vietbong87 vietbong87 is offline Offline
Newbie Poster

Re: help with finding minimum value

 
0
  #3
May 14th, 2006
thanks heaps ur a champ!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC