1.
Optional: Little Mac is an interplanetary space boxer, who is trying to win
championship belts for various weight categories on other planets within the
solar system.
Write a space.cpp program that helps him keep track of
his target weight by:
1. It should ask him
what his earth weight is.
2. Ask him to enter a
number for the planet he wants to fight on.
3. It should then
compute his weight on the destination planet.
Here is the table of conversion:
|
# |
Planet |
Relative Gravity |
|
1 |
Mercury |
0.38 |
|
2 |
Venus |
0.91 |
|
3 |
Mars |
0.38 |
|
4 |
Jupiter |
2.34 |
|
5 |
Saturn |
1.06 |
|
6 |
Uranus |
0.92 |
|
7 |
Neptune |
1.19 |
Hint
To compute his weight on the planet he is fighting on, multiply his
earth weight and the relative gravity of that planet.
Try using both if, else if, else and a switch statement!
Answer:
#include <iostream>
int main() {
double weight;
int x;
std::cout << "Please
enter your current earth weight: ";
std::cin >> weight;
std::cout << "\nI
have information for the following planets:\n\n";
std::cout << " 1. Venus
2. Mars 3. Jupiter\n";
std::cout << " 4. Saturn
5. Uranus 6. Neptune\n\n";
std::cout << "Which
planet are you visiting? ";
std::cin >> x;
if (x == 1) {
weight = weight * 0.78;
} else if (x == 2) {
weight = weight * 0.39;
} else if (x == 3) {
weight = weight * 2.65;
} else if (x == 4) {
weight = weight * 1.17;
} else if (x == 5) {
weight = weight * 1.05;
} else if (x == 6) {
weight = weight * 1.23;
}
std::cout << "\nYour
weight: " << weight
<< "\n";
}
Comments
Post a Comment