//Diego Martinez CSC5 Chapter 4, P.223,#15
/*******************************************************************************
* DISPLAY PERSONAL BEST HEIGHT
* ______________________________________________________________________________
* The program asks the user to enter the name of a pole vaulter, along with the
* dates and heights (in meters) of the athlete's three best vaults. It ensures
* that each height entered is within the valid range of 2.0 to 5.0 meters by
* checking the input and prompting the user agian if the value is outside this
* range.
*
* Computation is based on the Formula:
* Order runners by increasing time:
* bestHeight : 1st place
* secondHeight : 2nd place
* thirdHeight : 3rd place
* ____________________________________________________________________________
* INPUT
* Athlete's Name
* Dates Vaulted : 3 dates of different atttempted vaults
* Height of Vault : 3 diferent heights (Between 2.0 - 5.0 meters)
*
* OUTPUT
* 1st Best : athlete's best height
* 2nd Best : athlete's second best height
* 3ed Best : athlete's third best height
*******************************************************************************/
#include <iostream>
#include <string>
using namespace std;
int main() {
string name;
string date1, date2, date3;
double height1, height2, height3;
// Get athlete name
cout << "Enter the name of the pole vaulter: ";
getline(cin, name);
// Input dates and heights with validation
cout << "Enter the date of vault 1: ";
getline(cin, date1);
cout << "Enter the height (in meters): ";
cin >> height1;
while (height1 < 2.0 || height1 > 5.0) {
cout << "Invalid height. Enter a value between 2.0 and 5.0: ";
cin >> height1;
}
cin.ignore();
cout << "Enter the date of vault 2: ";
getline(cin, date2);
cout << "Enter the height (in meters): ";
cin >> height2;
while (height2 < 2.0 || height2 > 5.0) {
cout << "Invalid height. Enter a value between 2.0 and 5.0: ";
cin >> height2;
}
cin.ignore();
cout << "Enter the date of vault 3: ";
getline(cin, date3);
cout << "Enter the height (in meters): ";
cin >> height3;
while (height3 < 2.0 || height3 > 5.0) {
cout << "Invalid height. Enter a value between 2.0 and 5.0: ";
cin >> height3;
}
// Sorting (highest to lowest)
string bestDate, secondDate, thirdDate;
double bestHeight, secondHeight, thirdHeight;
if (height1 >= height2 && height1 >= height3) {
bestHeight = height1;
bestDate = date1;
if (height2 >= height3) {
secondHeight = height2;
secondDate = date2;
thirdHeight = height3;
thirdDate = date3;
} else {
secondHeight = height3;
secondDate = date3;
thirdHeight = height2;
thirdDate = date2;
}
}
else if (height2 >= height1 && height2 >= height3) {
bestHeight = height2;
bestDate = date2;
if (height1 >= height3) {
secondHeight = height1;
secondDate = date1;
thirdHeight = height3;
thirdDate = date3;
} else {
secondHeight = height3;
secondDate = date3;
thirdHeight = height1;
thirdDate = date1;
}
}
else {
bestHeight = height3;
bestDate = date3;
if (height1 >= height2) {
secondHeight = height1;
secondDate = date1;
thirdHeight = height2;
thirdDate = date2;
} else {
secondHeight = height2;
secondDate = date2;
thirdHeight = height1;
thirdDate = date1;
}
}
// Output results
cout << "\nPersonal Bests for " << name << ":\n";
cout << "1st (Best): " << bestDate << " - " << bestHeight << " meters\n";
cout << "2nd: " << secondDate << " - " << secondHeight << " meters\n";
cout << "3rd: " << thirdDate << " - " << thirdHeight << " meters\n";
return 0;
}