//Max Kichuk CS1A Chapter 4, P. 223, #14
//
/****************************************************************
*
* FINDS FIRST, SECOND, AND THIRD PLACE RUNNERS IN A RACE
* ______________________________________________________________
* Asks the user to enter the times and names of three runners
* and then displays who came in first, second, and third
* according to their times.
* ______________________________________________________________
*
* INPUT
* nameOfRunner1 : name of first runner
* nameOfRunner2 : name of second runner
* nameOfRunner3 : name of third runner
*
* timeOfRunner1 : time of first runner
* timeOfRunner2 : time of second runner
* timeOfRunner3 : time of third runner
*
* OUTPUT
* places of the runners according to times
*
**************************************************************/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
//Declaring program variables
string nameOfRunner1; // INPUT : name of first runner
string nameOfRunner2; // INPUT : name of second runner
string nameOfRunner3; // INPUT : name of third runner
float timeOfRunner1; // INPUT : time of first runner
float timeOfRunner2; // INPUT : time of second runner
float timeOfRunner3; // INPUT : time of third runner
// INPUT : Initialize variables
cout << "Enter the name of the first runner and their time ";
cout << "separated by a space.\n";
cin >> nameOfRunner1 >> timeOfRunner1;
cout << "Enter the name of the second runner and their time ";
cout << "separated by a space.\n";
cin >> nameOfRunner2 >> timeOfRunner2;
cout << "Enter the name of the third runner and their time ";
cout << "separated by a space.\n";
cin >> nameOfRunner3 >> timeOfRunner3;
// Checks if any of the values are negative.
if ((timeOfRunner1 < 0) || (timeOfRunner2 < 0) || (timeOfRunner3 < 0)) {
cout << "\nYou cannot have negative values for time! Please try again.";
return 0;
}
// OUTPUT : checks how many books were purchased and returns points
if (timeOfRunner1 > timeOfRunner2) {
if (timeOfRunner1 > timeOfRunner3) {
if (timeOfRunner2 > timeOfRunner3) {
cout << "First Place: " << setw(10) << nameOfRunner3 << endl;
cout << "Second Place: " << setw(10) << nameOfRunner2 << endl;
cout << "Third Place: " << setw(10) << nameOfRunner1 << endl;
}
else {
cout << "First Place: " << setw(10) << nameOfRunner2 << endl;
cout << "Second Place: " << setw(10) << nameOfRunner3 << endl;
cout << "Third Place: " << setw(10) << nameOfRunner1 << endl;
}
}
else {
cout << "First Place: " << setw(10) << nameOfRunner2 << endl;
cout << "Second Place: " << setw(10) << nameOfRunner1 << endl;
cout << "Third Place: " << setw(10) << nameOfRunner3 << endl;
}
}
else {
if (timeOfRunner2 > timeOfRunner3) {
if (timeOfRunner3 > timeOfRunner1) {
cout << "First Place: " << setw(10) << nameOfRunner1 << endl;
cout << "Second Place: " << setw(10) << nameOfRunner3 << endl;
cout << "Third Place: " << setw(10) << nameOfRunner2 << endl;
}
else {
cout << "First Place: " << setw(10) << nameOfRunner3 << endl;
cout << "Second Place: " << setw(10) << nameOfRunner1 << endl;
cout << "Third Place: " << setw(10) << nameOfRunner2 << endl;
}
}
else {
cout << "First Place: " << setw(10) << nameOfRunner1 << endl;
cout << "Second Place: " << setw(10) << nameOfRunner2 << endl;
cout << "Third Place: " << setw(10) << nameOfRunner3 << endl;
}
}
return 0;
}