Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is the code i have but it says error on the bolded part, help /******************************************************* * Program prompts the user to enter his/her weight

image text in transcribed

this is the code i have but it says error on the bolded part, help

/*******************************************************

* Program prompts the user to enter his/her weight *

* and the name of the planet. It uses enum to identify *

* planet name and computes the weight on that planet *

* and displays it to the user *

*******************************************************/

//header files section

#include

using namespace std;

//enumarated type declaration to represent planets

enum planetNames{Mercury, Venus, Earth, Moon, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto};

//function prototypes

planetNames findPlanetName(string str);

double calcWeight(planetNames, double);

int main()

{

//variable declaration

double weight;

double weightOnPlanet;

string planetName;

//display planet names to the user

cout

//prompt user to enter his/her weight and the name of a planet

cout

cin>>planetName;

cout

cin>>weight;

weightOnPlanet =calcWeight(findPlanetName(planetName),weight);

//display the planet name, weight on that planet

cout

//pause the system

system("pause");

return 0;

}

//function to find the planet name

//if the planet name enter is valid then it retuens the correspoinding enum value

planetNames findPlanetName(string str)

{

enum planetNames name = Earth;

//check the planet name is valid or not

// based on the length

if(str.length()

{

cout

cout

system("Pause");

exit(1);

}

//switch case to find the name of the

//planet correspoinding to the string

switch (toupper(str.at(0)))

{

case 'M':

switch (toupper(str.at(1)))

{

case 'E':

name = Mercury;

break;

case 'A':

name = Mars;

break;

case 'O':

name = Moon;

break;

defult:

cout

system("pause");

exit(1);

}

case 'V':

name = Venus;

break;

case 'E':

name = Earth;

break;

case 'J':

name = Jupiter;

break;

case 'S':

name = Saturn;

break;

case 'U':

name = Uranus;

break;

case 'N':

name = Neptune;

case 'P':

name = Pluto;

break;

default:

cout

cout

system ("Pause");

exit(1);

}

return name;

}

//funtion to calcualte the weight of a person on the planet of his choice

double calcWeight(planetNames planet, double weight)

{

double weightonPlanet = 0;

//switch case is used to identify the planet

//using enum value and calculate the weight on the planet

switch(planet)

{

case Mercury:

weightonPlanet = weight*0.4155;

break;

case Venus:

weightonPlanet = weight*0.8975;

break;

case Earth:

weightonPlanet = weight*1.0;

break;

case Moon:

weightonPlanet = weight*0.166;

break;

case Mars:

weightonPlanet = weight*0.3507;

break;

case Jupiter:

weightonPlanet = weight*2.5374;

break;

case Saturn:

weightonPlanet = weight*1.0677;

break;

case Uranus:

weightonPlanet = weight*0.8947;

break;

case Neptune:

weightonPlanet = weight*1.1794;

break;

case Pluto:

weightonPlanet = weight*0.0899;

break;

}

//return the weight on that planet

return weightonPlanet;

}

1. Programming Problem 4 in Chapter 5 asked you write a C+t progra user to enter his or her weight and the name of a planet. In Problem 2 asked you to rewrite the program using a Switch st the program so it uses an enumerated type to represent the Chapter 7, Programming rewrite is repeated here. The planetNOw, For ease of reference, the information for the original prob eight must be multiplied for each planet. following table gives the factor by which the weight must be m The program should output an error message if the user doesn't input a corn name. The prompt and the error message should make it clear to the user how name must be entered. Be sure to use proper formatting and appropriate comment your code. The output should be labeled clearly and formatted neatly correct pla net 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 Pluto0.0899

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

3. Who would the members be?

Answered: 1 week ago

Question

What was the role of the team leader? How was he or she selected?

Answered: 1 week ago