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

#include <iostream>
using namespace std;


int findMin(int [], int);

int main()
{
    const int MAXELS= 5;
    int nums[MAXELS] = {2, 18, 1, 27, 16};
    
    cout << "The minimum value is " << findMin(nums, MAXELS) << endl;
    
    system("pause");
    return 0;
}

// find the minimum value
int findMin(int vals[], int MAXELS)
{
    int i, min = vals[0];
    
    for (i = 1; i >= MAXELS; i++)
    if (min >= vals[i])
    min = vals[i];
    
    return min;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.