Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.13 KB | None | 0 0
  1. /*
  2.  * Author: Kylan Byrd
  3.  *
  4.  * Find the level of the atmosphere for a certain altitude.
  5.  *
  6.  * V-0.1 Date: 9/18/2017
  7.  * V-0.2 Date: 9/18/2017
  8.  *
  9.  * Compile with g++ -sted=c++11 -Wall -o atmosphere atmosphere.cpp
  10.  */
  11.  
  12. #include <iostream>
  13. #include <string>
  14. #include <limits>
  15.  
  16. using namespace std;
  17.  
  18. //Declare constant strings for messages to display to the user during use of the program, as well as .
  19.  
  20. //Messages for selection of measurement metric.
  21. const string UNIT_OF_MEASURE = "Which unit of measurement would you like to use? [0 = Miles, 1 = Metric]";
  22. const string UNIT_VALIDATION = "That was an invalid option. Please try again.";
  23.  
  24. //Set variables for measurement system.
  25. const int MILES = 0;
  26. const int METRIC = 1;
  27.  
  28. //Set variable for unit validation.
  29. bool unit_validation_check = false;
  30. int wanted_unit;
  31.  
  32. //Messages for user input of height.
  33. const string REQEUST_HEIGHT = "What is the height in question? [Use only numbers]";
  34. const string HEIGHT_VALIDATION = "That was an invalid entry. Please try again using only numbers.";
  35.  
  36. //Declare variable for user input.
  37. float height;
  38.  
  39. //Messages for atmospheric level.
  40. const string SURFACE_MESSAGE = " is on the surface, which is at the bottom of the Troposphere.";
  41. const string UNDERGROUND_MESSAGE = " is underground. This is not in the atmosphere.";
  42. const string OUTERSPACE_MESSAGE = " is in outerspace. This is not in the atmosphere, as it is past the Exosphere which is the highest level.";
  43. const string TROPOSPHERE_MESSAGE = " is in the Troposphere. This is the lowest level of the atmosphere.";
  44. const string STRATOSPHERE_MESSAGE = " is in the Stratosphere. This is the second lowest level of the atmosphere.";
  45. const string MESOSPHERE_MESSAGE = " is in the Mesosphere. This is the middle level of the atmosphere.";
  46. const string THERMOSPHERE_MESSAGE = " is in the Thermosphere. This is the second highest level of the atmosphere.";
  47. const string EXOSPHERE_MESSAGE = " is in the Exosphere. This is the highest level of the atmosphere.";
  48.  
  49. //Set atmospheric values.
  50. const int SURFACE = 0;
  51.  
  52. const int TROPOSPHERE_METRIC = 12;
  53. const int TROPOSPHERE_MILES = 7;
  54.  
  55. const int STRATOSPHERE_METRIC = 50;
  56. const int STRATOSPHERE_MILES = 31;
  57.  
  58. const int MESOSPHERE_METRIC = 80;
  59. const int MESOSPHERE_MILES = 50;
  60.  
  61. const int THERMOSPHERE_METRIC = 700;
  62. const int THERMOSPHERE_MILES = 440;
  63.  
  64. const int EXOSPHERE_METRIC = 10000;
  65. const int EXOSPHERE_MILES = 6200;
  66.  
  67. //Set max
  68. const int MAX_FLOAT_VALUE = std::numeric_limits<float>::max();
  69.  
  70. int main()
  71. {
  72.     //Determine unit of measure.
  73.     do
  74.     {
  75.         unit_validation_check = false; //Reset the flag to false for the following condition check.
  76.         cout << UNIT_OF_MEASURE << endl;
  77.         cin >> wanted_unit;
  78.  
  79.         //Check for failure status.
  80.         if ( cin.fail() )
  81.         {
  82.             cin.clear(); //Clear the input buffer.
  83.             unit_validation_check = true; //Change the flag to trigger the loop.
  84.         }
  85.  
  86.     }
  87.     //Loop until user inputs acceptable option.
  88.     while (( unit_validation_check || wanted_unit < 0 || wanted_unit > 1 ) && cout << UNIT_VALIDATION << endl );
  89.  
  90.     //Calculate Atmospheric layer, and print result.
  91.     if (height < 0 || height > 6200)
  92.     {
  93.         cout << height
  94.              << " miles is not in the atmosphere."
  95.              << endl;
  96.     }
  97.     else if ( height <= 7 )
  98.     {
  99.         cout << height
  100.              << " miles is in the Troposphere."
  101.              << endl;
  102.     }
  103.     else if ( height <= 31 )
  104.     {
  105.         cout << height
  106.              << " miles is in the Stratosphere."
  107.              << endl;
  108.     }
  109.     else if ( height <= 50 )
  110.     {
  111.         cout << height
  112.              << " miles is in the Mesosphere."
  113.              << endl;
  114.     }
  115.     else if ( height <= 440 )
  116.     {
  117.         cout << height
  118.              << " miles is in the Thermosphere."
  119.              << endl;
  120.     }
  121.     else if ( height <= 6200 )
  122.     {
  123.         cout << height
  124.              << " miles is in the Exosphere."
  125.              << endl;
  126.     }
  127.     else
  128.     {
  129.         cout << "I don't think "
  130.              << height
  131.              << "is what I asked for."
  132.              << endl;
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement