fork download
  1. //Diego Martinez CSC5 Chapter 4, P.223,#15
  2. /*******************************************************************************
  3. * DISPLAY PERSONAL BEST HEIGHT
  4. * ______________________________________________________________________________
  5. * The program asks the user to enter the name of a pole vaulter, along with the
  6. * dates and heights (in meters) of the athlete's three best vaults. It ensures
  7. * that each height entered is within the valid range of 2.0 to 5.0 meters by
  8. * checking the input and prompting the user agian if the value is outside this
  9. * range.
  10. *
  11. * Computation is based on the Formula:
  12. * Order runners by increasing time:
  13. * bestHeight : 1st place
  14. * secondHeight : 2nd place
  15. * thirdHeight : 3rd place
  16. * ____________________________________________________________________________
  17. * INPUT
  18. * Athlete's Name
  19. * Dates Vaulted : 3 dates of different atttempted vaults
  20. * Height of Vault : 3 diferent heights (Between 2.0 - 5.0 meters)
  21. *
  22. * OUTPUT
  23. * 1st Best : athlete's best height
  24. * 2nd Best : athlete's second best height
  25. * 3ed Best : athlete's third best height
  26. *******************************************************************************/
  27. #include <iostream>
  28. #include <string>
  29. using namespace std;
  30.  
  31. int main() {
  32. string name;
  33. string date1, date2, date3;
  34. double height1, height2, height3;
  35.  
  36. // Get athlete name
  37. cout << "Enter the name of the pole vaulter: ";
  38. getline(cin, name);
  39.  
  40. // Input dates and heights with validation
  41. cout << "Enter the date of vault 1: ";
  42. getline(cin, date1);
  43. cout << "Enter the height (in meters): ";
  44. cin >> height1;
  45. while (height1 < 2.0 || height1 > 5.0) {
  46. cout << "Invalid height. Enter a value between 2.0 and 5.0: ";
  47. cin >> height1;
  48. }
  49. cin.ignore();
  50.  
  51. cout << "Enter the date of vault 2: ";
  52. getline(cin, date2);
  53. cout << "Enter the height (in meters): ";
  54. cin >> height2;
  55. while (height2 < 2.0 || height2 > 5.0) {
  56. cout << "Invalid height. Enter a value between 2.0 and 5.0: ";
  57. cin >> height2;
  58. }
  59. cin.ignore();
  60.  
  61. cout << "Enter the date of vault 3: ";
  62. getline(cin, date3);
  63. cout << "Enter the height (in meters): ";
  64. cin >> height3;
  65. while (height3 < 2.0 || height3 > 5.0) {
  66. cout << "Invalid height. Enter a value between 2.0 and 5.0: ";
  67. cin >> height3;
  68. }
  69.  
  70. // Sorting (highest to lowest)
  71. string bestDate, secondDate, thirdDate;
  72. double bestHeight, secondHeight, thirdHeight;
  73.  
  74. if (height1 >= height2 && height1 >= height3) {
  75. bestHeight = height1;
  76. bestDate = date1;
  77.  
  78. if (height2 >= height3) {
  79. secondHeight = height2;
  80. secondDate = date2;
  81. thirdHeight = height3;
  82. thirdDate = date3;
  83. } else {
  84. secondHeight = height3;
  85. secondDate = date3;
  86. thirdHeight = height2;
  87. thirdDate = date2;
  88. }
  89. }
  90. else if (height2 >= height1 && height2 >= height3) {
  91. bestHeight = height2;
  92. bestDate = date2;
  93.  
  94. if (height1 >= height3) {
  95. secondHeight = height1;
  96. secondDate = date1;
  97. thirdHeight = height3;
  98. thirdDate = date3;
  99. } else {
  100. secondHeight = height3;
  101. secondDate = date3;
  102. thirdHeight = height1;
  103. thirdDate = date1;
  104. }
  105. }
  106. else {
  107. bestHeight = height3;
  108. bestDate = date3;
  109.  
  110. if (height1 >= height2) {
  111. secondHeight = height1;
  112. secondDate = date1;
  113. thirdHeight = height2;
  114. thirdDate = date2;
  115. } else {
  116. secondHeight = height2;
  117. secondDate = date2;
  118. thirdHeight = height1;
  119. thirdDate = date1;
  120. }
  121. }
  122.  
  123. // Output results
  124. cout << "\nPersonal Bests for " << name << ":\n";
  125. cout << "1st (Best): " << bestDate << " - " << bestHeight << " meters\n";
  126. cout << "2nd: " << secondDate << " - " << secondHeight << " meters\n";
  127. cout << "3rd: " << thirdDate << " - " << thirdHeight << " meters\n";
  128.  
  129. return 0;
  130. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty