Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Original Specifications:
Write a program that prompts the user to enter a length in inches. Calculate and display
the length in centimeters. Use a constant for the conversion factor of 2.54. HINT: Multiply
the input value by 2.54.
The program output should look like this for the input value 12:

Now write a program that prompts the user to enter a length in centimeters. Calculate and
display the length in centimeters. Use a constant for the conversion factor of 2.54. Write
the same program that converts centimeters to inches. HINT: Divide the input value by
2.54.

The program output should look like this for the input value 30.48
Enter a length in inches: 12
12 inches = 30.48 centimeters

Enter a length in centimeters: 30.48
30.48 centimeters = 12 inches

Revised Specifications:
Modify the program above to prompt the user for the type of conversion to be performed
(i.e. Inches to Centimeters or Centimeters to Inches) and the value to be converted.

Create three methods:
1. inchesToCentimeters()‐ takes the number entered by the user, and returns the
result of the number multiplied by 2.54.
2. centimetersToInches()()‐ takes the number entered by the user, and returns the
result of the number divided by 2.54.
3. DisplayResults() – takes the type of conversion, the number entered by the
user and the conversion result and displays the appropriate message to the screen.

Your output should look like this:
Conversion Type:
1 - inches to centimeters
2 - centimeters to inches
Enter the type of conversion to perform: 1
Enter a length in inches: 12
12 inches = 30.48 centimeters.

What I have tried:

I don't understand how to add the 3 methods and how to put it into effect.
Posted
Updated 8-Aug-22 7:27am
v3
Comments
Richard Deeming 9-Aug-22 8:57am    
Removing the content of your question after it has been answered is extremely rude, and will not prevent your teachers from discovering your attempt to cheat on your homework.

I have reverted your destructive edit.

1 solution

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900