So, I coded this in an exercise, and whenever I run it, let’s say I put in 100 pounds for weight, it multiplies earthWeight to get a number that isn’t correct. If I put in 100 for weight and 1 for Mercury, I get 12445 pounds. I had a similar issue with a different calculator type code the other day, so does anyone know what I’m doing wrong?
Edit: the output for Mercury and Mars are different for 100 pounds, even though they should be the same.
Here’s the code, I’m fairly certain the switch part is correct, it’s just the variables I’m having trouble with:
#include
int main() {
//variables
int earthWeight;
int planetNumber;
float mercuryWeight = earthWeight * 0.38;
float venusWeight = earthWeight * 0.91;
float marsWeight = earthWeight * 0.38;
float jupiterWeight = earthWeight * 2.34;
float saturnWeight = earthWeight * 1.06;
float uranusWeight = earthWeight * 0.92;
float neptuneWeight = earthWeight * 1.19;
//planets
std::cout << “1 = Mercury\n”;
std::cout << “2 = Venus\n”;
std::cout << “3 = Mars\n”;
std::cout << “4 = Jupiter\n”;
std::cout << “5 = Saturn\n”;
std::cout << “6 = Uranus\n”;
std::cout << “7 = Neptune\n”;
//main code
std::cout << “Enter your earth weight:\n”;
std::cin >> earthWeight;
std::cout << “Enter a planet number:\n”;
std::cin >> planetNumber;
switch (planetNumber){
case 1:
std::cout << “Your weight on Mercury would be " << mercuryWeight << " pounds\n”;
break;
case 2:
std::cout << “Your weight on Venus would be " << venusWeight << " pounds\n”;
break;
case 3:
std::cout << “Your weight on Mars would be " << marsWeight << " pounds\n”;
break;
case 4:
std::cout << “Your weight on Jupiter would be " << jupiterWeight << " pounds\n”;
break;
case 5:
std::cout << “Your weight on Saturn would be " << saturnWeight << " pounds\n”;
break;
case 6:
std::cout << “Your weight on Uranus would be " << uranusWeight << " pounds\n”;
break;
case 7:
std::cout << “Your weight on Neptune would be " << neptuneWeight << " pounds\n”;
break;
default:
std::cout << “Invalid\n”;
break;
}
}