my program takes in values from a input file and passes them to an array called gpa. I have created a function that finds the smallest value in the gap array and displays it, but I also need to display a duplicate value if there is one. How would I do this.
Thank you in advance
#include <iostream>
#include <fstream>
using namespace std;
void lowestGpa(string names[], double gpa[], int SIZE){
int count;
double lowest = gpa[0];
string name;
for (count = 0; count < SIZE; count++)
{
if (gpa[count] <= lowest)
{
lowest = gpa[count];
name = names[count];
}
}
cout << name << " " << lowest;
}
int main()
{
ifstream infile;
infile.open("GPA.txt");
int const SIZE = 15;
string names[SIZE];
double gpa[SIZE];
while (infile)
{
for(int i = 0; i < SIZE; i++)
{
infile >> names[i] >> gpa[i];
}
}
lowestGpa(names, gpa, SIZE);
infile.close();
return 0;
}
std::min_elementalgorithm and astd::adjacent_findalgorithm, which tells you exactly where adjacent equal elements are.