Unit Conversion: Length (Meters to Kilometers, Centimeters, etc.)

  • Input and Menu Display:
    • The program first displays a menu with three options for converting meters to kilometers, centimeters, or millimeters.
    • The user is prompted to enter their choice.
  • Switch Statement:
    • The program uses a switch statement to determine which conversion to perform based on the user’s choice.
    • Each case corresponds to a different unit conversion:
      • case 1: Converts meters to kilometers by dividing the length in meters by 1000.
      • case 2: Converts meters to centimeters by multiplying the length in meters by 100.
      • case 3: Converts meters to millimeters by multiplying the length in meters by 1000.
    • If the user enters an invalid choice, the default case is executed, printing an error message.
  • Output:
    • The program calculates the result based on the conversion and prints it to the console.

      Example 1: Convert Meters to Kilometers

      Input:

      • Choice: 1
      • Meters: 1500

      Output:

      Example 2: Convert Meters to Centimeters

      Input:

      • Choice: 2
      • Meters: 2.5

      Output:

      Example 3: Convert Meters to Millimeters

      Input:

      • Choice: 3
      • Meters: 0.75

      Output:

      Example 4: Invalid Choice

      Input:

      • Choice: 4
      • Meters: 100

      Output: