/* Running Race - This program asks for the names of three runners and the time
it took each of them to finish a race. The program displays who came in first,
second, and third place.
Input Validation: Only positive numbers for times are accepted. */
#include "Utility.h"
int main()
{
/* Hold three names */
string nameRunnerOne = " ",
nameRunnerTwo = " ",
nameRunnerThree = " ";
/* Hold three times */
int timeRunnerOne = 0,
timeRunnerTwo = 0,
timeRunnerThree = 0;
/* Ask for three names and three times */
cout << "Enter name for runner one: ";
cin >> nameRunnerOne;
cout << "Enter finishing time of runner one: ";
cin >> timeRunnerOne;
cout << "Enter name for runner two: ";
cin >> nameRunnerTwo;
cout << "Enter finishing time of runner two: ";
cin >> timeRunnerTwo;
cout << "Enter name for runner three: ";
cin >> nameRunnerThree;
cout << "Enter finishing time of runner three: ";
cin >> timeRunnerThree;
/* Determine which runner is first, second and third */
if (!(timeRunnerOne < 1 || timeRunnerTwo < 1 || timeRunnerThree < 1))
{
if (timeRunnerOne < timeRunnerTwo && timeRunnerTwo < timeRunnerThree)
{
/* 1, 2, 3 */
cout << "\nFirst place goes to:\t\t" << nameRunnerOne
<< "\nHis/her finishing time is:\t" << timeRunnerOne << " minutes.\n"
<< "Second place two goes to:\t" << nameRunnerTwo
<< "\nHis/her finishing time is:\t" << timeRunnerTwo << " minutes.\n"
<< "Third place goes to:\t\t" << nameRunnerThree
<< "\nHis/her finishing time is :\t" << timeRunnerThree << " minutes.\n";
}
else if (timeRunnerOne < timeRunnerThree && timeRunnerThree < timeRunnerTwo)
{
/* 1, 3, 2 */
cout << "\nFirst place goes to:\t\t" << nameRunnerOne
<< "\nHis/her finishing time is:\t" << timeRunnerOne << " minutes.\n"
<< "Second place two goes to:\t" << nameRunnerThree
<< "\nHis/her finishing time is:\t" << timeRunnerThree << " minutes.\n"
<< "Third place goes to:\t\t" << nameRunnerTwo
<< "\nHis/her finishing time is :\t" << timeRunnerTwo << " minutes.\n";
}
else if (timeRunnerTwo < timeRunnerOne && timeRunnerOne < timeRunnerThree)
{
/* 2, 1, 3 */
cout << "\nFirst place goes to:\t\t" << nameRunnerTwo
<< "\nHis/her finishing time is:\t" << timeRunnerTwo << " minutes.\n"
<< "Second place two goes to:\t" << nameRunnerOne
<< "\nHis/her finishing time is:\t" << timeRunnerOne << " minutes.\n"
<< "Third place goes to:\t\t" << nameRunnerThree
<< "\nHis/her finishing time is :\t" << timeRunnerThree << " minutes.\n";
}
else if (timeRunnerTwo < timeRunnerThree && timeRunnerThree < timeRunnerOne)
{
/* 2, 3, 1 */
cout << "\nFirst place goes to:\t\t" << nameRunnerTwo
<< "\nHis/her finishing time is:\t" << timeRunnerTwo << " minutes.\n"
<< "Second place two goes to:\t" << nameRunnerThree
<< "\nHis/her finishing time is:\t" << timeRunnerThree << " minutes.\n"
<< "Third place goes to:\t\t" << nameRunnerOne
<< "\nHis/her finishing time is :\t" << timeRunnerOne << " minutes.\n";
}
else if (timeRunnerThree < timeRunnerOne && timeRunnerOne < timeRunnerTwo)
{
/* 3, 1, 2 */
cout << "\nFirst place goes to:\t\t" << nameRunnerThree
<< "\nHis/her finishing time is:\t" << timeRunnerThree << " minutes.\n"
<< "Second place two goes to:\t" << nameRunnerOne
<< "\nHis/her finishing time is:\t" << timeRunnerOne << " minutes.\n"
<< "Third place goes to:\t\t" << nameRunnerTwo
<< "\nHis/her finishing time is :\t" << timeRunnerTwo << " minutes.\n";
}
else if (timeRunnerThree < timeRunnerTwo && timeRunnerTwo < timeRunnerOne)
{
/* 3, 2, 1 */
cout << "\nFirst place goes to:\t\t" << nameRunnerThree
<< "\nHis/her finishing time is:\t" << timeRunnerThree << " minutes.\n"
<< "Second place two goes to:\t" << nameRunnerTwo
<< "\nHis/her finishing time is:\t" << timeRunnerTwo << " minutes.\n"
<< "Third place goes to:\t\t" << nameRunnerOne
<< "\nHis/her finishing time is :\t" << timeRunnerOne << " minutes.\n";
}
}
else
{
cout << "You entered invalid times! Only positive numbers are accepted!\n";
}
pauseSystem();
return 0;
}
Tuesday, November 22, 2016
Programming Challenge 4.16 - Running Race
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment