Advertisement
marcusziade

Untitled

Jan 27th, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. enum class Planet {
  4. Mercury = 1,
  5. Venus,
  6. Earth,
  7. Mars,
  8. Jupiter,
  9. Saturn,
  10. Uranus,
  11. Neptune
  12. };
  13.  
  14. std::istream &operator>>(std::istream &is, Planet &planet) {
  15. std::int8_t n;
  16. is >> n;
  17. switch (n) {
  18. case 1:
  19. planet = Planet::Mercury;
  20. break;
  21. case 2:
  22. planet = Planet::Venus;
  23. break;
  24. case 3:
  25. planet = Planet::Earth;
  26. break;
  27. case 4:
  28. planet = Planet::Mars;
  29. break;
  30. case 5:
  31. planet = Planet::Jupiter;
  32. break;
  33. case 6:
  34. planet = Planet::Saturn;
  35. break;
  36. case 7:
  37. planet = Planet::Uranus;
  38. break;
  39. case 8:
  40. planet = Planet::Neptune;
  41. break;
  42. default:
  43. break;
  44. }
  45. return is;
  46. }
  47.  
  48. double planet_gravity_multiplier(Planet p) {
  49. switch (p) {
  50. case Planet::Mercury:
  51. return 0.38;
  52. case Planet::Venus:
  53. return 0.91;
  54. case Planet::Earth:
  55. return 1.0;
  56. case Planet::Mars:
  57. return 0.38;
  58. case Planet::Jupiter:
  59. return 2.34;
  60. case Planet::Saturn:
  61. return 1.06;
  62. case Planet::Uranus:
  63. return 0.92;
  64. case Planet::Neptune:
  65. return 1.19;
  66. default:
  67. break;
  68. }
  69. }
  70.  
  71. std::string planet_name(Planet p) {
  72. switch (p) {
  73. case Planet::Mercury:
  74. return "Mercury";
  75. case Planet::Venus:
  76. return "Venus";
  77. case Planet::Earth:
  78. return "Earth";
  79. case Planet::Mars:
  80. return "Mars";
  81. case Planet::Jupiter:
  82. return "Jupiter";
  83. case Planet::Saturn:
  84. return "Saturn";
  85. case Planet::Uranus:
  86. return "Uranus";
  87. case Planet::Neptune:
  88. return "Neptune";
  89. default:
  90. break;
  91. }
  92. }
  93.  
  94. int main() {
  95. double earth_weight;
  96. Planet planet_number;
  97. double competing_weight;
  98.  
  99. std::cout << "Enter your weight on Earth:\n";
  100. std::cin >> earth_weight;
  101.  
  102. std::cout << "Which planet in our solar system do you want to fight on?\n";
  103. std::cout << "1: Mercury\n2: Venus\n3: Earth\n4: Mars\n5: Jupiter\n6: "
  104. "Saturn\n7: Uranus\n8: Neptune\n";
  105. std::cin >> planet_number;
  106.  
  107. competing_weight = earth_weight * planet_gravity_multiplier(planet_number);
  108.  
  109. std::cout << "Your competing weight is " << competing_weight << " kg.";
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement