Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that asks the user to enter the number corresponds for a planet name and their weight on earth (in pounds).

 

Write a C++ program that asks the user to enter the number corresponds for a planet name and their weight on earth (in pounds). The chosen planet will be selected from a menu displayed, and then enter the value for the weight in earth in pounds. The program will then calculate and then output the corresponding weight in the planet selected by multiplying the weight on earth by the weight multiplier for the planet selected. Weight multipliers are listed in the table below. The program should output an error message if the user doesn't type a valid number that corresponds to a planet name. (See sample run below). In addition, check to ensure that weight is greater than 0. The prompt and the error message should make it clear to the user how a planet name must be entered. Be sure to use proper formatting and appropriate comments in your code. The output should be clearly labeled and neatly formatted. Planet Name Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Weight Multiplier 0.4155 0.8975 1.0 0.3507 2.5374 1.0677 0.8947 1.1794 Remember Don't Repeat Yourself (DRY) in your code. Set the weight multiplier depending on which planet entered and then calculate and print the weight only once. A sample run of the program will produce something like this: 1) Mercury 2) Venus 3) Earth 4) Mars 5) Jupiter 6) Saturn 7) Uranus 8) Neptune Enter for planet: 0 You entered an invalid number; it should be a number from 1 to 8. Enter for planet: 9 You entered an invalid number; it should be a number from 1 to 8. Enter for planet: -1 You entered an invalid number; it should be a number from 1 to 8. Enter for planet: 7 Enter your weight in pounds: -100 Weight must be greater than 0. Enter your weight in pounds: 100 You will weigh 89.47 pounds on planet Uranus.

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

Starting Out With Java From Control Structures Through Data Structures

Authors: Tony Gaddis

6th Edition

0133957055, 978-0133957051

More Books

Students also viewed these Computer Network questions