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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/*
COP 2000
HW 4 Race Results
3/25/2018*/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//what will be used below with functions
void getRaceTimes(string &, double &);
void findWinner(string, string, string, double, double, double);
void welcome();
double raceAverage(double, double, double);
bool validate_user_input(double);
int main()
{
//these are the variables
string racerName, racer1, racer2, racer3;
double raceTime, time1, time2, time3;
welcome();
getRaceTimes(racerName, raceTime);
findWinner(racer1, racer2, racer3, time1 = 0, time2 = 0, time3 = 0);
raceAverage(time1, time2, time3);
return 0;
}
void welcome()
{
//this displays the welcome prompt
cout << "***********************************\n";
cout << "Welcome to Race Results Program\n";
cout << "You are Asked to Enter the Three Racer's Names\n";
cout << "and Their Associated Race Time.\n\n";
cout << "Please enther a real number for Race Time (the Race Time Must be > 0)";
cout << "\n\nProgram Developed by: :)\n";
cout << "***********************************\n";
}
void getRaceTimes(string &racerName, double &raceTime)
{
cout << "Please enter the racer's first name > ";
cin >> racerName;
cout << "Please enter the racer's time >";
cin >> raceTime;
cout << "Please enter the racer's second name > ";
cin >> racerName;
cout << "Please enter the racer's time >";
cin >> raceTime;
cout << "Please enter the racer's third name > ";
cin >> racerName;
cout << "Please enter the racer's time >";
cin >> raceTime;
while (raceTime <= 0)
cout << "Invalid. Please try again.";
cin >> raceTime;
}
void findWinner(string racer1, string racer2, string racer3, double time1, double time2, double time3)
{
//this will display after the names and times have been
if ((time1 < time2) && (time1 < time3))
{
cout << "Congratulations " << racer1 << "!!! You are the winner!!\n";
cout << "***** Your winning time is: " << time1 << " *****";
if ((time2 < time1) && (time2 < time3))
{
cout << "Congratulations " << racer2 << "!!! You are the winner!!\n";
cout << "***** Your winning time is: " << time2 << " *****";
if ((time3 < time1) && (time3 < time2))
{
cout << "Congratulations " << racer3 << "!!! You are the winner!!\n";
cout << "***** Your winning time is: " << time3 << " *****";
//because these times tie, only displaying one of the times//
if ((time1 < time3) && (time1 == time2))
{
cout << "We have a TIE, " << racer1 << "and" << racer2 << "!!\n";
cout << "***** Your winning time is: " << time1 << " *****";
if ((time1 < time2) && (time1 == time3))
{
cout << "We have a TIE, " << racer1 << "and" << racer3 << "!!\n";
cout << "***** Your winning time is: " << time1 << " *****";
{
if ((time2 < time1) && (time2 == time3))
{
cout << "We have a TIE, " << racer2 << "and" << racer3 << "!!\n";
cout << "***** Your winning time is: " << time2 << " *****";
if ((time1 == time2 && time2 == time3))
{
cout << "We have a 3 TIE!! No winner for this race...\n";
}
}
}
}
}
}
}
}
}
double raceAverage(double time1, double time2, double time3)
{
//this is gonna calculate the average of the racers times//
double raceAverage = (time1 + time2 + time3) / 3.0;
cout << "Overall Race Time Average: " << raceAverage << "\n";
return raceAverage;
}
|