# Thread: Functions that compares strings

1. ## Functions that compares strings

My problem is in the display skiers time function I am not sure how to compare strings.
Code:
```#include <iostream>
#include <string>

using namespace std;

int displayFastestSkier(string name[], double time[])
{
int x=0;
int fastestTime = 1000;
for (x=0; x<5; x++)
if (time[x] < fastestTime)
{
fastestTime = time[x];
}
return fastestTime;
}

int displayAvgTime(double time[])
{
int total, x, avg = total/5;
time[x] += total;
return avg;
}

int displaySkiersTime(string name[],double time[])
{
int x;
string skier;
for (x=0; x<5; x++)
{
if (skier != name[x])
else if (skier == name[x])
return name[x], time[x];
}
}

int displaySkiersAndTimes(string name[],  double time[])
{
int x = 0;
for (x=0; x<5; x++)
{
cout << "Name "<< "      " << "Time" << endl;
cout << name[x] << "        " << time[x] << endl;
}

}

int main()
{
int x = 0, option;
const int SIZE = 5;
double time[SIZE];
string name[SIZE];

for (x=0; x<SIZE; x++)
{
cout << "Enter the skier's name: " << endl;
cin >> name[x];
cout << "Enter the skier's time: " << endl;
cin >> time[x];

}
cout << endl;
cout << "*************   MENU   *************" << endl;
cout << "1: Find the fastest skier. " << endl;
cout << "2: Calculate average time. " << endl;
cout << "3: Find the time of a skier. " << endl;
cout << "4: Display the skiers and thier times. " << endl;
cout << "************************************" << endl;
cout << "Enter choice";
cin >> option;
//logic
if (option == 1)
{
cout << "Fastsest time is " << displayFastestSkier(name, time) << endl;
}
else if (option == 2)
{
cout << "The average time is " << displayAvgTime(time) << endl;
}
else if (option == 3)
{
cout << "Skier: " <<  name[x] << " Time: " << time[x] <<endl;
}
else if (option == 4)
{
displaySkiersAndTimes(name, time);
}

return 0;
}```

2. >> My problem is in the display skiers time function I am not sure how to compare strings.
You are comparing them correctly in that function. That is not your problem. The good thing about the string type is that you can easily compare with != and ==.

>> return name[x], time[x];
This is not what you want.

Also, think about all your functions named displayXXX. Are they all meant to display something? Or are some meant to lookup some value and return it? If it's the latter, maybe better naming will make things easier going forward.

3. Code:
```int displayFastestSkier(string name[], double time[])
// How is 'name' used in this function?
{
int x = 0;
int fastestTime = 1000; // Why 1000?
for (x=0; x<5; x++) // Why 5?
if (time[x] < fastestTime)
{
fastestTime = time[x];
}
return fastestTime;
}```
```double fastestTime(const std::vector<double>& times)