Message to PhantomJoe: Don't use other people's code unless you understand how it works, professors can easily spot the cheaters by asking some questions about the program they supposedly wrote.
That said, as long as we propose improvements, I would go for an array to hold all the different planet values, and index it with the value the user gives. I'm not going for efficiency, I genuinely think this implementation is easier to read and to be understood, as well as easily modifiable:
Code:
#include <stdio.h>
int main()
{
float objectWeight; //declare the variable for the object's weight
int planet; //declare the variable for the planet number
int i;
const char* planetNames[] = {
"Mercury", "Venus", "Earth", "Earth's Moon", "Mars",
"Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"
};
const double planetRatios[] = {
0.4155, 0.8975, 1.0, 0.166, 0.3507,
2.5374, 1.0677, 0.8947, 1.1794, 0.0899
};
printf("Enter an object's weight in pounds.\n");
scanf("%f", &objectWeight); //read the value from the end user
//Print the below menu to the screen
printf("\n"
"Please choose from the following menu one of the bodies found in our solar\n"
"system by entering it's corresponding number.\n");
// Print all available planets
for (i = 0; i < sizeof(planetRatios)/sizeof(planetRatios[0]); ++i) {
printf("%d. %s\n", i+1, planetNames[i]);
}
putchar('\n');
scanf("%d", &planet); //read the planet number from the user
printf("\n");
if (planet > 0 && planet <= sizeof(planetRatios)/sizeof(planetRatios[0])) {
printf("The weight of this object on %s is %f.\n", planetNames[planet-1], objectWeight * planetRatios[planet-1]);
}
return 0;
}