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])
cout << "Name not found!" << endl;
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];
}
//menu
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;
}