I am supposed to write a program that asks for the name of a pole vaulter and the dates and vault heights ( in meters) of the athlete’s three best vaults. It should then report in height order ( best first), the date on which each vault was made, and its height. Input Validation: Only accept values between 2.0 and 5.0 for the heights.
I have been working on this for hours and trying so many different things! Please help! I have no idea how to put the results in highest to lowest order, and I thought I had the input validation right, but when I type a number greater than 5.0 ( or even one within the range of 2.0 to 5.0 the program shuts down (though when I type a number less than 2.0, it works fine!).
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Define variables.
string name;
string month;
string day;
string year;
bool height;
// Get inputs.
// Get the name of the pole vaulter.
cout << "Enter the first and last name of the pole vaulter: \n";
cin >> name >> name;
// Get the date of the first vault.
cout << " Enter the numeric month, day, and year of the first vault, putting a space between each entry: \n";
cin >> month >> day >> year;
// Get the height of the first vault.
cout << " Enter the height (between 2.0 and 5.0 meters) of the first vault: \n";
cin >> height;
// Do not accept valutes greater than 5.0
if (height > 5.0)
{
cout << " The number you entered is too large. \n";
height = false;
}
// Do not accept values less than 2.0
if (height < 2.0)
{
cout << " The number you entered is too small. \n";
height = false;
}
// Get the date of the second vault.
cout << " Enter the numeric month, day, and year of the second vault, putting a space between each entry: \n";
cin >> month >> day >> year;
// Get the height of the second vault.
cout << " Enter the height (between 2.0 and 5.0 meters) of the second vault: \n";
cin >> height;
//Do not accept valutes greater than 5.0
if (height > 5.0)
{
cout << " The number you entered is too large. \n";
height = false;
}
// Do not accept values less than 2.0
if (height < 2.0)
{
cout << " The number you entered is too small. \n";
height = false;
}
// Get the date of the third vault.
cout << " Enter the numeric month, day, and year of the third vault, putting a space between each entry: \n";
cin >> month >> day >> year;
// Get the height of the third vault.
cout << " Enter the height (between 2.0 and 5.0 meters) of the third vault: \n";
cin >> height;
//Do not accept valutes greater than 5.0
if (height > 5.0)
{
cout << " The number you entered is too large. \n";
height = false;
}
// Do not accept values less than 2.0
if (height < 2.0)
{
cout << " The number you entered is too small. \n";
height = false;
cin.ignore();
cin.get();
}
if (height == true)
{
cout << " The height of the best vault was " << height << " meters and was made on " << month << "/"
<< day << "/" << year << " . \n";
cout << " The height of the second best vault was " << height << " meters and was made on " << month << "/"
<< day << "/" << year << " . \n";
cout << " The height of the third best vault was " << height << " meters and was made on " << month << "/"
<< day << "/" << year << " . \n";
cin.ignore();
cin.get();
}
return 0;
}