Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 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, MOON, 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. switch (planet)
  49. {
  50. case MERCURY:
  51. cout << userWeight * 0.4155 << endl;
  52. break;
  53. case VENUS:
  54. cout << userWeight * 0.8975 << endl;
  55. break;
  56. case EARTH:
  57. cout << userWeight * 1.0 << endl;
  58. break;
  59. case MOON:
  60. cout << userWeight * 0.166 << endl;
  61. break;
  62. case MARS:
  63. cout << userWeight * 0.3507 << endl;
  64. break;
  65. case JUPITER:
  66. cout << userWeight * 2.5374 << endl;
  67. break;
  68. case SATURN:
  69. cout << userWeight * 1.0677 << endl;
  70. break;
  71. case URANUS:
  72. cout << userWeight * 0.8947 << endl;
  73. break;
  74. case NEPTUNE:
  75. cout << userWeight * 1.1794 << endl;
  76. break;
  77. case PLUTO:
  78. cout << userWeight * 0.0899 << endl;
  79. break;
  80. default:
  81. break;
  82. }
  83.  
  84.  
  85. //Closing program statements
  86. return 0;
  87. }
  88.  
  89. bool ValidPlanet(string userInput, PlanetType& planet)
  90. {
  91. if (userInput == "MERCURY")
  92. {
  93. planet = MERCURY;
  94. return true;
  95. }
  96. else if (userInput == "VENUS")
  97. {
  98. planet = VENUS;
  99. return true;
  100. }
  101. else if (userInput == "EARTH")
  102. {
  103. planet = EARTH;
  104. return true;
  105. }
  106. else if (userInput == "MOON")
  107. {
  108. planet = MOON;
  109. return true;
  110. }
  111. else if (userInput == "MARS")
  112. {
  113. planet = MARS;
  114. return true;
  115. }
  116. else if (userInput == "JUPITER")
  117. {
  118. planet = JUPITER;
  119. return true;
  120. }
  121. else if (userInput == "SATURN")
  122. {
  123. planet = SATURN;
  124. return true;
  125. }
  126. else if (userInput == "URANUS")
  127. {
  128. planet = URANUS;
  129. return true;
  130. }
  131. else if (userInput == "NEPTUNE")
  132. {
  133. planet = NEPTUNE;
  134. return true;
  135. }
  136. else if (userInput == "PLUTO")
  137. {
  138. planet = PLUTO;
  139. return true;
  140. }
  141. else
  142. {
  143. cout << "Error: invalid entry" << endl;
  144. return false;
  145. }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement