1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
# include <iostream>
# include <string>
using namespace std;
void welcome();
void getRaceTimes(string&, string&, string&, double&, double&, double&);
double raceAverage(double, double, double);
void findWinner(string &, double &, string, string, string, double, double, double);
int main()
{
string name1, name2, name3;
double time1 = 0, time2 = 0, time3 = 0;
string winnerName;
double winningTime = 0;
welcome();
getRaceTimes(name1, name2, name3, time1, time2, time3);
double average = raceAverage(time1, time2, time3);
cout << "Average: " << average << endl;
findWinner(winnerName, winningTime, name1, name2, name3, time1, time2, time3);
cout << " Winner: " << winnerName << endl;
cout << " Time: " << winningTime << endl;
return 0;
}
void getRaceTimes(string &n1, string &n2, string &n3, double &t1, double &t2, double &t3)
{
cout << "Please enter racer ones name: \n ";
cin >> n1;
cout << "Enter racer ones time: \n";
cin >> t1;
cout << "Please enter racer twos name: \n ";
cin >> n2;
cout << "Enter racer twos time: \n";
cin >> t2;
cout << "Please enter racer threes name: \n";
cin >> n3;
cout << "Please enter racer threes time: \n";
cin >> t3;
return;
}
void findWinner(string &wn, double &wt, string n1, string n2, string n3, double t1, double t2, double t3)
{
wn = n1;
wt = t1;
if (t2 < wt)
{
wt = t2;
wn = n2;
}
if (t3 < wt)
{
wt = t3;
wn = n3;
}
return;
}
void welcome()
{
cout << "*****************************************************************************\n";
cout << "Welcome to Race Results Program\n";
cout << "You are Asked to Enter the Three Racers Names and their Associated Race Time\n " << endl;
cout << "Please enter a real number for the Race Time (the race time must be > 0)\n";
cout << "Program Developed by: Samantha Cartossa\n";
cout << "******************************************************************************\n" << endl;
return;
}
double raceAverage( double t1, double t2, double t3)
{
return (t1 + t2 + t3)/3;
}
|