# Thread: Finding minimum in Array (2 equal minimums)

1. ## Finding minimum in Array (2 equal minimums)

hello!

I am writing a program to find the minimum value in an array that is within an int function. There are two elements in the array that have the same value and I need to be able to output them both. However, the way my function code is written as far as I understand is that it will only store the location of the minimum it encounters and it seems to ignore the second one. This makes sense to me as the function can only return one value. I define the location as loc = function(variables) in main. I tried using a for loop before I output the university/local tuition corresponding to that location I just calculated but it seems to only still output the first minimum.

So how can I write this so it returns both? I am only showing the code that is relevant here

Code:
```int main()
{
string uni[MAX], state[MAX], city[MAX];
int enroll[MAX], number, loc;
//Null here is actually percent of students accepted but will not be used in anything hence nickname of null
double avgTuition, lowest;
ifstream inFile;
ofstream outFile;

loc = lowTuit(uni, yearlytuit, number);
cout << uni[loc] << yearlytuit[loc];

int lowTuit(string uni[], double yearlytuit[], int number)
{
int loc;
string univ;
double lowest = yearlytuit;
for (int i = 0; i < number; i++)
{
if (lowest > yearlytuit[i])
{
lowest = yearlytuit[i];
loc = i;
}
}
return loc;
}``` 2. There is no way to do it right.

But, you could write another function that returns all the values that are less than or equal to the lowest value.

Tim S. 3. Originally Posted by stahta01 There is no way to do it right.

But, you could write another function that returns all the values that are less than or equal to the lowest value.

Tim S.
Is there no way to use maybe a for condition in the main when I am asking it to cout << uni[loc] << yearlytuit[loc] ? 4. Never mind. I have figured it out Popular pages Recent additions array, function, int, location, minimum 