This program will give the user two options – to convert centimeters to inches, inches to centimeters, or to exit. Ask the user if they’d like to convert cm to inches, inches to cm, or if they’d like to exit. If they choose to convert, ask them for their numeric input, do the math, and output the result to them. The loop should then repeat and the menu should be reprinted for them to select again. If they choose to exit, the program should end cleanly. (“Cleanly” means we do not ask for more input or do any math. However, you are encouraged to add a “goodbye” statement.) If they choose an invalid option for the menu, tell them that they entered an invalid option, reprint the menu, and let them enter again. You do not have to account for negative centimeters. Simply do the math and let a negative answer be given. Use a while loop to complete this program. Consider using an if/else statement inside your loop. Consider using a Boolean variable to control the loop. Program should be able to accept real numbers and output should be decimal formatted. Sample output: This program will convert units of measurements Type 1 if you want to convert cm to inches. Type 2 if you want to convert inches to cm. Type 3 if you want to exit the program. >>>1 Enter your number in centimeters: >>>30.0 This is equal to 11.81 inches. Type 1 if you want to convert cm to inches. Type 2 if you want to convert inches to cm. Type 3 if you want to exit the program. >>>2 Enter your number in inches: >>>100 This is equal to 254.00 cm. Type 1 if you want to convert cm to inches. Type 2 if you want to convert inches to cm. Type 3 if you want to exit the program. >>>5 Invalid Input. Type 1 if you want to convert cm to inches. Type 2 if you want to convert inches to cm. Type 3 if you want to exit the program. >>>3 Goodbye. in java
This
- Ask the user if they’d like to convert cm to inches, inches to cm, or if they’d like to exit.
- If they choose to convert, ask them for their numeric input, do the math, and output the result to them. The loop should then repeat and the menu should be reprinted for them to select again.
- If they choose to exit, the program should end cleanly. (“Cleanly” means we do not ask for more input or do any math. However, you are encouraged to add a “goodbye” statement.)
- If they choose an invalid option for the menu, tell them that they entered an invalid option, reprint the menu, and let them enter again.
- You do not have to account for negative centimeters. Simply do the math and let a negative answer be given.
- Use a while loop to complete this program. Consider using an if/else statement inside your loop. Consider using a Boolean variable to control the loop. Program should be able to accept real numbers and output should be decimal formatted.
Sample output:
This program will convert units of measurements
Type 1 if you want to convert cm to inches.
Type 2 if you want to convert inches to cm.
Type 3 if you want to exit the program.
>>>1
Enter your number in centimeters:
>>>30.0
This is equal to 11.81 inches.
Type 1 if you want to convert cm to inches.
Type 2 if you want to convert inches to cm.
Type 3 if you want to exit the program.
>>>2
Enter your number in inches:
>>>100
This is equal to 254.00 cm.
Type 1 if you want to convert cm to inches.
Type 2 if you want to convert inches to cm.
Type 3 if you want to exit the program.
>>>5
Invalid Input.
Type 1 if you want to convert cm to inches.
Type 2 if you want to convert inches to cm.
Type 3 if you want to exit the program.
>>>3
Goodbye.
in java
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images