Drop links or images here to add them to the editor.

A simple measurement conversion utility.

★★★

The unica was one-twelfth of a Roman foot. In 1324 the legal definition of the inch was set out in a statute of Edward II of England, defining it as "three grains of barley, dry and round, placed end to end, lengthwise". At various times the inch has also been defined as the combined lengths of 12 poppyseeds. Since 1959 the inch has been defined officially as 2.54cm.

Measurements

Make

Write a program that converts feet to inches and inches to feet. The user should be prompted to enter the conversion they require.

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Create a subprogram called feet_to_inches that:

  1. Takes a parameter feet and returns inches calculated as feet multipled by twelve.

Create a subprogram called inches_to_feet that:

  1. Takes a parameter inches and returns feet calculated as inches divided by twelve.

Create a subprogram called menu that:

  1. Prints the menu options 1, 2, 3 and reads the user’s choice.
  2. The user should be continually re-asked until they make a valid input “1”, “2” or “3”.

Create a subprogram called converter that:

  1. Presents the menu to the user.
  2. If the user chooses option 1 it reads a decimal number of feet and outputs the number of inches.
  3. If the user chooses option 2 it reads a number of inches and outputs the number of feet.
  4. If the user chooses option 3 it outputs, “Goodbye”.

Complete the main program so that:

  1. It calls the converter subprogram.

Typical inputs and outputs from the program would be:

1. Feet to inches
2. Inches to feet
3. Quit
Enter choice:
1
Enter the number of feet:
3
3 feet is 36 inches.
1. Feet to inches
2. Inches to feet
3. Quit
Enter choice:
2
Enter the number of inches:
72
72 inches is 6 feet.
1. Feet to inches
2. Inches to feet
3. Quit
Enter choice:
3
Goodbye
🆘 If you're really stuck, use this Parsons code sorting exercise
Complete program
// Measurements program

using System;

class Submission
{
---
    // -------------------------
    // Subprograms
    // -------------------------
    // Convert feet to inches
    static double feet_to_inches(double feet)
    {
---
        return feet * 12;
---
    }
---


    // Convert inches to feet
    static double inches_to_feet(double inches)
    {
---
        return inches / 12;
---
    }
---


    // Offer the conversion choice to the user
    static string menu()
    {
---
        string menu_choice = "0";
        // Iterate until a valid option is chosen
        while (menu_choice != "1" && menu_choice != "2" && menu_choice != "3")
        {
---
            Console.WriteLine("1. Feet to inches");
            Console.WriteLine("2. Inches to feet");
            Console.WriteLine("3. Quit");
            Console.WriteLine("Enter choice:");
            menu_choice = Console.ReadLine();
---
        }
---
        return menu_choice;
---
    }
---


    // Call conversion routines from user's choice
    static void converter()
    {
---
        string option = menu();
        double feet;
        double inches;
        // Act on the chosen option
        switch (option)
        {
---
            // Feet to inches
            case "1":
                Console.WriteLine("Enter the number of feet:");
                feet = Convert.ToDouble(Console.ReadLine());
                inches = feet_to_inches(feet);
                Console.WriteLine($"{feet} feet is {inches} inches.");
                break;
---
            // Inches to feet
            case "2":
                Console.WriteLine("Enter the number of inches:");
                inches = Convert.ToDouble(Console.ReadLine());
                feet = inches_to_feet(inches);
                Console.WriteLine($"{inches} inches is {feet} feet.");
                break;
---
            // Quit
            case "3":
                Console.WriteLine("Goodbye");
                break;
---
        }
---
    }
---


    // -------------------------
    // Main program
    // -------------------------
    public static void Main(string[] args)
    {
---
        converter();
---
    }
---
}