Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in C language that displays menus for converting length and calc

ID: 3662451 • Letter: W

Question

Write a program in C language that displays menus for converting length and calculates the result. The program should support the following conversions:

Miles Kilometers 1.6093

Kilometers Miles 0.6214

Inches Centimeters 2.54

Centimeters Inches 0.3937

1. Display the menu options as numbers.

1 - Miles to Kilometers

2 – Kilometers to Miles

3 - Inches to Centimeters

4 – Centimeters to Inches

2. Use a switch statement for option selection and calculation.

3. If the entered option is not in the range of 1 to 4, display an error message and abort the program.

4. The output should display two digits after the decimal point. For example, 3.23.

Explanation / Answer

Answer -

#include <stdio.h>
int main(void)
{
int choice,length;
float output;
printf(" LENGTH CONVERTER");
printf(" 1 - Miles to Kilometers");
printf(" 2 – Kilometers to Miles");
printf(" 3 - Inches to Centimeters");
printf(" 4 – Centimeters to Inches");
   printf(" Enter Choice : ");
   scanf("%d",&choice);
   switch(choice)
{
   case 1 :
   printf(" Enter length in Miles: ");
   scanf("%d",&length);
   output=length*1.6093;
   printf(" Converted length in Kilometers : %.2f",output);
   break;
   case 2 :
   printf(" Enter length in Kilometers: ");
   scanf("%d",&length);
   output=length*0.6214;
   printf(" Converted length in Miles : %.2f",output);
   break;
   case 3 :
   printf(" Enter length in Inches: ");
   scanf("%d",&length);
   output=length*2.54;
   printf(" Converted length in Centimeters : %.2f",output);
   break;
   case 4 :
   printf(" Enter length in Centimeters: ");
   scanf("%d",&length);
   output=length*0.3937;
   printf(" Converted length in Inches : %.2f",output);
   break;
   default:
   printf(" Wrong Choice Entered!! ");
}
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote