Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Write a program that uses one or more if statements and a loops to solve the following problem: Prompt the user for a number (type

image text in transcribed

Write a program that uses one or more if statements and a loops to solve the following problem: Prompt the user for a number (type double) and the type of conversion calculation to apply. You will continue to prompt for conversions until the user enters a code of "XX". Once the user supplies the value and the type of conversion, your program should apply the appropriate conversion and display the result. For the conversion type, the user will enter one of the following conversion codes: GL, IC, PK, MK. Based on the user's input, your program will compute and display the appropriate result. See below for the meaning of the codes: GL = Gallon to Liter IC = Inch to Centimeter PK = Pound to Kilogram MK = Mile to Kilometer For instance, if the user inputs GL as their conversion type, the program will then take their numeric input as gallons and convert it to liters. The liter's value would then be output to the user. Please find additional information below to assist you in solving this problem: 1 Gallon = 3.78541178 Liters 1 Inch = 2.5 Centimeters 1 Pound = 0.45359237 Kilograms 1 Mile = 1.609344 Kilometers Use the try-catch idea to only allow numeric input for conversion amount...if a user does not enter a valid number the program should inform the user and force the correct input. Likewise, if a user does not enter a valid Conversion Type the program should inform the user and force correct input. When comparing the user's input for conversion type, make sure that you use the EQUALSIGNORECASE method as described in class. I will test with a variety of numbers and all conversion types User MUST enter amount before type. When the user has entered a number and a good conversion code your output should look like this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions