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
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int SIZE=16;
char f1[SIZE], f2[SIZE], f3[SIZE], l1[SIZE], l2[SIZE], l3[SIZE];
double t1, t2, t3;
cout << "This program will put the best three runner\n"
"in order of their finishing time."
"\nPlease enter runners' details.\n\n"
"***WARNING***: Last names and first names will be displayed with\n"
"the first 15 characters only and miliseconds will be displayed with\n"
"three decimal points only.\n\n";
cout << "Runner Number 1 Details\n"
"-----------------------\n"
"Last Name : ";
cin.getline(l1, SIZE);
cout << "\nFirst Name : ";
cin.getline(f1, SIZE);
cout << "\nFinish Time(In Seconds): ";
cin >> t1;
cout << "Runner Number 1 Details\n"
"-----------------------\n"
"Last Name : ";
cin.ignore();
cin.getline(l2, SIZE);
cout << "\nFirst Name : ";
cin.getline(f2, SIZE);
cout << "\nFinish Time(In Seconds): ";
cin >> t2;
cout << "Runner Number 1 Details\n"
"-----------------------\n"
"Last Name : ";
cin.ignore();
cin.getline(l3, SIZE);
cout << "\nFirst Name : ";
cin.getline(f3, SIZE);
cout << "\nFinish Time(In Seconds): ";
cin >> t3;
if (t1==t2||t1==t3||t2==t3||t1<=0||t2<=0||t3<=0)
{
cout << "\n\nEither you have entered the same finishing time for different runners\n"
"or one or more finishing time is smaller than or equal to 0.\n"
"Please restart the program and enter correct finishing times.\n\n";
system("pause");
return 0;
}
else
{
cout << "\n\nHere are the runners displayed according to their finishing time:\n\n";
if (t1<t2&&t1<t3)
{
if (t2<t3)
{
cout << "1. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << endl;
cout << "2. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << endl;
cout << "3. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << "\n\n";
}
else
{
cout << "1. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << endl;
cout << "2. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << endl;
cout << "3. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << "\n\n";
}
}
else if (t2<t1&&t2<t3)
{
if (t1<t3)
{
cout << "1. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << endl;
cout << "2. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << endl;
cout << "3. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << "\n\n";
}
else
{
cout << "1. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << endl;
cout << "2. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << endl;
cout << "3. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << "\n\n";
}
}
else
{
if (t2<t1)
{
cout << "1. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << endl;
cout << "2. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << endl;
cout << "3. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << "\n\n";
}
else
{
cout << "1. " << l3 << ", " << f3 << " " << fixed << setprecision(3) << t3 << endl;
cout << "2. " << l1 << ", " << f1 << " " << fixed << setprecision(3) << t1 << endl;
cout << "3. " << l2 << ", " << f2 << " " << fixed << setprecision(3) << t2 << "\n\n";
}
}
}
system("pause");
return 0;
}
|