Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. //Include statements
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <iomanip>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. //Global declarations: Constants and type definitions only -- no variables
  11.  
  12. enum PlanetType { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE, PLUTO };
  13.  
  14. //Function prototypes
  15.  
  16. bool ValidPlanet(string userInput, PlanetType& planet);
  17.  
  18. int main()
  19. {
  20. //In cout statement below substitute your name and lab number
  21. cout << "Christopher Kheir -- Lab 8" << endl << endl;
  22. //I have read and understand the Lab Submittal Policy on BB.
  23.  
  24.  
  25.  
  26. //Variable declarations
  27.  
  28. float userWeight;
  29. string userInput;
  30. PlanetType planet;
  31.  
  32. //Program logic
  33.  
  34. cout << "Please enter your weight: ";
  35. cin >> userWeight;
  36. cout << endl;
  37.  
  38.  
  39. do
  40. {
  41. cout << "Please enter a valid planet name from the list as shown. MERCURY , VENUS , EARTH , MARS , JUPITER , SATURN , URANUS , NEPTUNE , PLUTO : ";
  42. cin>>userInput;
  43. planet = EARTH;
  44.  
  45.  
  46. } while (!ValidPlanet(userInput,planet));
  47.  
  48.  
  49.  
  50.  
  51. //Closing program statements
  52. return 0;
  53. }
  54.  
  55. bool ValidPlanet(string userInput, PlanetType& planet)
  56. {
  57. if(userInput == "MERCURY")
  58. {
  59. planet = MERCURY;
  60. return true;
  61. }
  62. else if(userInput == "VENUS")
  63. {
  64. planet = VENUS;
  65. return true;
  66. }
  67. else if(userInput == "EARTH")
  68. {
  69. planet = EARTH;
  70. return true;
  71. }
  72. else if(userInput == "MARS")
  73. {
  74. planet = MARS;
  75. return true;
  76. }
  77. else if(userInput == "JUPITER")
  78. {
  79. planet = JUPITER;
  80. return true;
  81. }
  82. else if(userInput == "SATURN")
  83. {
  84. planet = SATURN;
  85. return true;
  86. }
  87. else if(userInput == "URANUS")
  88. {
  89. planet = URANUS;
  90. return true;
  91. }
  92. else if(userInput == "NEPTUNE")
  93. {
  94. planet = NEPTUNE;
  95. return true;
  96. }
  97. else if(userInput == "PLUTO")
  98. {
  99. planet = PLUTO;
  100. return true;
  101. }
  102. else
  103. {
  104. cout<<"Error: invalid entry"<<endl;
  105. return false;
  106. }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement