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 90 91 92 93
|
# include <iostream>
# include <string>
using namespace std;
//function prototyping
void getRaceTimes(string&, double&);
void findWinner(string, string, string, double, double, double);
void welcome();
double raceAverage(double, double, double);
int main()
{
string name1, name2, name3;
double time1, time2, time3;
welcome();
getRaceTimes(name1, time1);
getRaceTimes(name2, time2);
getRaceTimes(name3, time3);
findWinner(name1, name2, name3, time1, time2, time3);
double average = raceAverage(time1, time2, time3);
cout << endl;
cout << endl;
cout << "Race time average is: " << average << endl;
return 0;
}
//function definition
void getRaceTimes(string&racerName, double&racerTime)
{
cout >> "Please enter the 1st racer's name"
cin << name1
cout >> "Please enter the racer's time"
cin << time1
cout >> "Please enter the 2nd racer's name"
cin << name2
cout >> "Please enter the racer's time"
cin << time2
cout >> "Please enter the 3rd racer's name"
cin << name3
cout >> "Please enter the racer's time"
cin << time3
while (racerTime <= 0)
{
cout << "Invalid time, please enter a valid time"
}
void findWinner(string racer1, string racer2, string racer3, double time1, double time2, double time3)
{
while (time1&&time2&&time3 > 0)
{
void getRaceTimes();
if (time1 > time2 && time1 > time3)
{
cout << "Racer one is the winner!";
}
else if (time2 > time1 && time2 > time3)
{
cout << "Racer two is the winner!";
}
else if (time3 > time1 && time3 > time2)
{
cout << "Racer three is the winner!";
}
else if (time1 == time2 > time3)
{
cout << "Racer 1 and 2 have tied";
}
else if (time1 == time3 > time2)
{
cout << "Racers 1 and 3 have tied!";
}
else if (time2 == time3 > time1)
{
cout << "Racers 2 and 3 have tied!";
}
}
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: SEND HELP\n";
cout << "******************************************************************************\n" << endl;
}
double raceAverage(double time1, double time2, double time3)
{
double average = (time1 + time2 + time3) / 3.0;
cout << "Race time average is: " << raceAverage << "";
return average;
}
|