Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Author: Kylan Byrd
- *
- * Find the level of the atmosphere for a certain altitude.
- *
- * V-0.1 Date: 9/18/2017
- * V-0.2 Date: 9/18/2017
- *
- * Compile with g++ -sted=c++11 -Wall -o atmosphere atmosphere.cpp
- */
- #include <iostream>
- #include <string>
- #include <limits>
- using namespace std;
- //Declare constant strings for messages to display to the user during use of the program, as well as .
- //Messages for selection of measurement metric.
- const string UNIT_OF_MEASURE = "Which unit of measurement would you like to use? [0 = Miles, 1 = Metric]";
- const string UNIT_VALIDATION = "That was an invalid option. Please try again.";
- //Set variables for measurement system.
- const int MILES = 0;
- const int METRIC = 1;
- //Set variable for unit validation.
- bool unit_validation_check = false;
- int wanted_unit;
- //Messages for user input of height.
- const string REQEUST_HEIGHT = "What is the height in question? [Use only numbers]";
- const string HEIGHT_VALIDATION = "That was an invalid entry. Please try again using only numbers.";
- //Declare variable for user input.
- float height;
- //Messages for atmospheric level.
- const string SURFACE_MESSAGE = " is on the surface, which is at the bottom of the Troposphere.";
- const string UNDERGROUND_MESSAGE = " is underground. This is not in the atmosphere.";
- const string OUTERSPACE_MESSAGE = " is in outerspace. This is not in the atmosphere, as it is past the Exosphere which is the highest level.";
- const string TROPOSPHERE_MESSAGE = " is in the Troposphere. This is the lowest level of the atmosphere.";
- const string STRATOSPHERE_MESSAGE = " is in the Stratosphere. This is the second lowest level of the atmosphere.";
- const string MESOSPHERE_MESSAGE = " is in the Mesosphere. This is the middle level of the atmosphere.";
- const string THERMOSPHERE_MESSAGE = " is in the Thermosphere. This is the second highest level of the atmosphere.";
- const string EXOSPHERE_MESSAGE = " is in the Exosphere. This is the highest level of the atmosphere.";
- //Set atmospheric values.
- const int SURFACE = 0;
- const int TROPOSPHERE_METRIC = 12;
- const int TROPOSPHERE_MILES = 7;
- const int STRATOSPHERE_METRIC = 50;
- const int STRATOSPHERE_MILES = 31;
- const int MESOSPHERE_METRIC = 80;
- const int MESOSPHERE_MILES = 50;
- const int THERMOSPHERE_METRIC = 700;
- const int THERMOSPHERE_MILES = 440;
- const int EXOSPHERE_METRIC = 10000;
- const int EXOSPHERE_MILES = 6200;
- //Set max
- const int MAX_FLOAT_VALUE = std::numeric_limits<float>::max();
- int main()
- {
- //Determine unit of measure.
- do
- {
- unit_validation_check = false; //Reset the flag to false for the following condition check.
- cout << UNIT_OF_MEASURE << endl;
- cin >> wanted_unit;
- //Check for failure status.
- if ( cin.fail() )
- {
- cin.clear(); //Clear the input buffer.
- unit_validation_check = true; //Change the flag to trigger the loop.
- }
- }
- //Loop until user inputs acceptable option.
- while (( unit_validation_check || wanted_unit < 0 || wanted_unit > 1 ) && cout << UNIT_VALIDATION << endl );
- //Calculate Atmospheric layer, and print result.
- if (height < 0 || height > 6200)
- {
- cout << height
- << " miles is not in the atmosphere."
- << endl;
- }
- else if ( height <= 7 )
- {
- cout << height
- << " miles is in the Troposphere."
- << endl;
- }
- else if ( height <= 31 )
- {
- cout << height
- << " miles is in the Stratosphere."
- << endl;
- }
- else if ( height <= 50 )
- {
- cout << height
- << " miles is in the Mesosphere."
- << endl;
- }
- else if ( height <= 440 )
- {
- cout << height
- << " miles is in the Thermosphere."
- << endl;
- }
- else if ( height <= 6200 )
- {
- cout << height
- << " miles is in the Exosphere."
- << endl;
- }
- else
- {
- cout << "I don't think "
- << height
- << "is what I asked for."
- << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement