|
| 1 | +//©Alexander Haislip, Wednesday March 27th 2020 |
1 | 2 | #include <iostream>
|
2 | 3 | #include <string>
|
3 | 4 | using namespace std;
|
4 | 5 |
|
| 6 | +// Function that calculates your weight on another planet |
| 7 | +double calc(double earthWeight, double rel) { |
| 8 | + return earthWeight * rel; |
| 9 | +} |
| 10 | + |
5 | 11 | int main() {
|
6 | 12 |
|
7 | 13 | double planet_Weight;
|
8 | 14 | double earth_Weight;
|
9 |
| - double calc = earth_Weight * planet_Weight; |
10 | 15 |
|
| 16 | +//This will take input from the user asking their current earth weight. |
11 | 17 | cout << "What is your weight on earth? LBS : ";
|
12 |
| - cin.clear();//you need to clear the flags before input |
13 |
| - getline (cin, earth_Weight); |
14 |
| - |
| 18 | + cin >> earth_Weight; |
15 | 19 |
|
16 |
| - std::cout << "Choose a relative gravity for the planet in which you want to know your weight on : Planet Relative Gravity Earth = 1 , Venus = 0.78 , Mars = 0.39 , Jupiter = 2.65 , Saturn = 1.17 , Uranus = 1.05 , Neptune = 1.23: \n"; |
17 |
| - cin.clear();//you need to clear the flags before input |
18 |
| - getline (cin, planet_Weight); |
| 20 | + int planet; |
| 21 | + std::cout << "Choose a planet in which you want to know your weight on :\n"; |
| 22 | + std::cout << "Mars => 1\nVenus => 2\nJupiter => 3\nSaturn => 4\nUranus => 5\nNeptune => 6\n"; |
| 23 | + cin >> planet; |
19 | 24 |
|
| 25 | + double planetMultiplier; |
| 26 | + string planetName; |
20 | 27 |
|
21 |
| - if (planet_Weight == 1) { |
22 |
| - cout << "Your weight on Earth is... " << calc; |
23 |
| - } else if (planet_Weight == 0.39) { |
24 |
| - cout << "Your weight on Mars is... " << calc; |
25 |
| - } else if (planet_Weight == 0.78) { |
26 |
| - cout << "Your weight on Venus is... " << calc; |
27 |
| - } else if (planet_Weight == 2.65) { |
28 |
| - cout << "Your weight on Jupiter is... " << calc; |
29 |
| - } else if (planet_Weight == 1.17) { |
30 |
| - cout << "Your weight on Saturn is... " << calc; |
31 |
| - } else if (planet_Weight == 1.05) { |
32 |
| - cout << "Your weight on Uranus is... " << calc; |
33 |
| - } else if (planet_Weight == 1.23) { |
34 |
| - cout << "Your weight on Neptune is... " << calc; |
35 |
| - } else { |
36 |
| - |
37 |
| - cout << "Your weight on this planet is Unknown... "; |
38 |
| - |
39 |
| - |
| 28 | + switch(planet) { |
| 29 | + case 1 : // Mars |
| 30 | + planetMultiplier = 0.78; |
| 31 | + planetName = "Mars"; |
| 32 | + break; |
| 33 | + case 2 : // Venus |
| 34 | + planetMultiplier = 2.65; |
| 35 | + planetName = "Venus"; |
| 36 | + break; |
| 37 | + case 3 : // Jupiter |
| 38 | + planetMultiplier = 1.17; |
| 39 | + planetName = "Jupiter"; |
| 40 | + break; |
| 41 | + case 4 : // Saturn |
| 42 | + planetMultiplier = 1.05; |
| 43 | + planetName = "Saturn"; |
| 44 | + break; |
| 45 | + case 5 : // Uranus |
| 46 | + planetMultiplier = 1.23; |
| 47 | + planetName = "Uranus"; |
| 48 | + break; |
| 49 | + case 6 : // Neptune |
| 50 | + planetMultiplier = 0.17; |
| 51 | + planetName = "Neptune"; |
| 52 | + break; |
| 53 | + |
| 54 | + |
40 | 55 | }
|
41 |
| - |
| 56 | + |
| 57 | + double newWeight = calc(earth_Weight, planetMultiplier); |
| 58 | + cout << "Your weight on " << planetName << " is " << newWeight << endl; |
| 59 | + |
42 | 60 | }
|
| 61 | + |
| 62 | + |
0 commit comments