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 yearlytuit[MAX], null[MAX], fresh[MAX], gradsix[MAX];
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[0];
for (int i = 0; i < number; i++)
{
if (lowest > yearlytuit[i])
{
lowest = yearlytuit[i];
loc = i;
}
}
return loc;
}