#include <iostream>
#include <string>
#include <iomanip> // For output formatting
using namespace std;
int main() {
// Variables to store the runners' names and their times
string runner1, runner2, runner3;
double time1, time2, time3;
// Ask for the names of the runners
cout << "Enter the name of the first runner: ";
getline(cin, runner1);
cout << "Enter the name of the second runner: ";
getline(cin, runner2);
cout << "Enter the name of the third runner: ";
getline(cin, runner3);
// Ask for the times it took each runner to finish
cout << "Enter the time (in seconds) for " << runner1 << ": ";
cin >> time1;
// Input validation for the time to be positive
if (time1 <= 0) {
cout << "Error: Time must be a positive number.\n";
return 1;
}
cout << "Enter the time (in seconds) for " << runner2 << ": ";
cin >> time2;
// Input validation for the time to be positive
if (time2 <= 0) {
cout << "Error: Time must be a positive number.\n";
return 1;
}
cout << "Enter the time (in seconds) for " << runner3 << ": ";
cin >> time3;
// Input validation for the time to be positive
if (time3 <= 0) {
cout << "Error: Time must be a positive number.\n";
return 1;
}
// Determine who came in first, second, and third place
string first, second, third;
double firstTime, secondTime, thirdTime;
// Find the first place
if (time1 < time2 && time1 < time3) {
first = runner1;
firstTime = time1;
if (time2 < time3) {
second = runner2;
secondTime = time2;
third = runner3;
thirdTime = time3;
} else {
second = runner3;
secondTime = time3;
third = runner2;
thirdTime = time2;
}
} else if (time2 < time1 && time2 < time3) {
first = runner2;
firstTime = time2;
if (time1 < time3) {
second = runner1;
secondTime = time1;
third = runner3;
thirdTime = time3;
} else {
second = runner3;
secondTime = time3;
third = runner1;
thirdTime = time1;
}
} else {
first = runner3;
firstTime = time3;
if (time1 < time2) {
second = runner1;
secondTime = time1;
third = runner2;
thirdTime = time2;
} else {
second = runner2;
secondTime = time2;
third = runner1;
thirdTime = time1;
}
}
// Display the results
cout << fixed << setprecision(2); // Set the time format to two decimal places
cout << "\nRace Results:\n";
cout << "-------------------------------------\n";
cout << "1st place: " << first << " with a time of " << firstTime << " seconds.\n";
cout << "2nd place: " << second << " with a time of " << secondTime << " seconds.\n";
cout << "3rd place: " << third << " with a time of " << thirdTime << " seconds.\n";
return 0;
}