Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

r 5 asked you anet. In Chapter 7, Programming program that asks t user to enter

ID: 3914840 • Letter: R

Question

r 5 asked you anet. In Chapter 7, Programming program that asks t user to enter his or her weight and the name of a planet. In C arogram that a Problem 2 asked you to rewrite the program using a Switch statemens rogram the program so it uses an enumerated type to represent the pl 1. Programming Problem 4 in Chapter 5 asked you write a C++ Now, rewrite For ease of reference, the information for the original proble following table gives the factor by which the weight must be mulicated here. The program should output an error message if the user doesn't input a cor name. The prompt and the error message should make it clear to the usepan name must be entered. Be sure to use proper formatting and appropriate commento your code. The output should be labeled clearly and formatted neatly. eight must be multiplied for each planet. how a plan et Mercury 0.4155 Venus 0.8975 Earth 1.0 Moon 0.166 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899

Explanation / Answer

#include <stdio.h>
#define MERCURY 0.4155
#define VENUS 0.8975
#define EARTH 1.0
#define MOON 0.166
#define MARS 0.3507
#define JUPITER 2.5374
#define SATURN 1.0677
#define URANUS 0.8947
#define NEPTUNE 1.1794
#define PLUTO 0.0899
//All the planet weights are defined to their name

int findPlanet(int);//finds which planet to calculate weight
double findPlanetWeight(int,int,double);//calculates weight
void printResult(int, double);//prints results including planet name and weight on said planet

void main()
{
   int planet = 0;//This will identify the planet
   int normalWeight = 0;//This is your normal EARTH weight
   double planetWeight = 0;//This will be the calculated weight on another planet


   planet = findPlanet(planet);

   printf(" Enter your weight in pounds:");
   scanf("%d", &normalWeight);//User enters their normal earth weight

       //If user enters a 0 then it loops again
   while (normalWeight < 1){
       printf(" Invalid Weight... Please enter value greater than ZERO");
       printf(" Enter your weight in whole pounds:");
       scanf("%d", &normalWeight);
   }
   planetWeight = findPlanetWeight(planet, normalWeight, planetWeight);

printResult(planet, planetWeight);

   return;
}


int findPlanet(int planet)
{
   printf("1) Mercury ");
   printf("2) Venus ");
   printf("3) Earth ");
   printf("4) Moon ");
   printf("5) Mars ");
   printf("6) Jupiter ");
   printf("7) Saturn ");
   printf("8) Uranus ");
   printf("9) Neptune ");

        printf("10) Pluto ");

      
   printf("Please enter 1-10 for planet number. ");
   scanf("%d", &planet);
//If an invalid planet number is entered it will loop until a valid number is entered
   while (planet != 1 && planet != 2 && planet != 3 && planet != 4 && planet != 5 && planet != 6 && planet != 7 && planet != 8 && planet != 9 && planet !=10 ){
       printf("Invalid entry... Please try again... ");
       printf("Please enter 1-10 for planet number. ");
       scanf("%d", &planet);
   }
   return(planet);
}
//This function calculates the weight on different planets based on what number was entered into the previous function
double findPlanetWeight(int planet, int normalWeight, double planetWeight)
{


   if (planet == 1){
           planetWeight = (MERCURY * normalWeight);
   }
   else if (planet == 2){
           planetWeight = (VENUS * normalWeight);
   }
   else if (planet == 3){
           planetWeight = (EARTH * normalWeight);
   }
   else if (planet == 4){
           planetWeight = (MOON * normalWeight);
   }
   else if (planet == 5){
           planetWeight = (MARS * normalWeight);
   }
   else if (planet == 6){
           planetWeight = (JUPITER * normalWeight);
   }
   else if (planet == 7){
           planetWeight = (SATURN * normalWeight);
   }
   else if (planet == 8){
           planetWeight = (URANUS * normalWeight);
   }
   else if (planet == 9){
           planetWeight = (NEPTUNE * normalWeight);
   }

        else if (planet == 10){
           planetWeight = (PLUTO * normalWeight);
   }

   return(planetWeight);
}
//This function will print the resulting weight and planet name.
void printResult(int planet, double planetWeight)
{
   if (planet == 1){
       printf(" Your weight on planet Mercury would be %.2f lbs. ", planetWeight);
   }
   else if (planet == 2){
       printf(" Your weight on planet Venus would be %.2f lbs. ", planetWeight);
   }
   else if (planet == 3){
       printf(" Your weight on planet Earth would be %.2f lbs. ", planetWeight);
   }
   else if (planet == 4){
       printf(" Your weight on the moon would be %.2f lbs. ", planetWeight);
   }
   else if (planet == 5){
       printf(" Your weight on planet Mars would be %.2f lbs. ", planetWeight);
   }
   else if (planet == 6){
       printf(" Your weight on planet Jupiter would be %.2f lbs. ", planetWeight);
   }
   else if (planet == 7){printf(" Your weight on planet Saturn would be %.2f lbs. ", planetWeight);
   }
   else if (planet == 8){
       printf(" Your weight on planet Uranus would be %.2f lbs. ", planetWeight);
   }
   else if (planet == 9){printf(" Your weight on planet Neptune would be %.2f lbs. ", planetWeight);
    }

        else if (planet == 10){printf(" Your weight on planet Pluto would be %.2f lbs. ", planetWeight);


   }
   return;
}