Write a conversion program that will display a menu to the user and allow the us
ID: 671946 • Letter: W
Question
Write a conversion program that will display a menu to the user and allow the user to choose to convert from Celsius to Fahrenheit, Fahrenheit to Celsius, miles to kilometers, or kilometers to miles. The program should perform the following steps: Use a do-while loop to continue running the program until the user selects to end the program. Display Menu of choices & read in users choice. Screen capture below: Validate users choice using a while loop. Use a switch statement to determine what to do with the users choice If user selects 1 (Fahrenheit to Celsius) Read in from the user the Fahrenheit value Call the calculate Celsius function, sending the Fahrenheit to the function. This function should return the celsuis. Print the result of the conversion as shown in screen capture in sample output. If user selects 2 through 4 - repeat the same process as in step e - performing the conversions by callin functions to do the calculations. If the user selects 5 - print out Bye! and the program should end.Explanation / Answer
#include<stdio.h>
double CalculateCelsius(double f){
return ((f-32)*(5.00/9.00));
}
double CalculateFahrenheit(double c){
return ((c)*(9.00/5.00)+32.00);
}
double CalculateMiles(double k){
return (0.62*k);
}
double CalculateKilometers(double m){
return (1.609*m);
}
int main()
{
int opt=0,flag=0;
double f,c,k,m;
do{
while(opt<1||opt>5){
printf("MAIN MENU ");
printf("1 - Convert Fahrenheit to Celsius ");
printf("2 - Convert Celsius to Fahrenheit ");
printf("3 - Convert Kilometers to Miles ");
printf("4 - Convert Miles to Kilometers ");
printf("5 - End Program ");
printf("Choose 1-5: ");
scanf("%d",&opt);
}
switch(opt){
case 1:
printf(" Please enter the temperature in fahrenheit: ");
scanf("%lf",&f);
c=CalculateCelsius(f);
printf("%.2lf degrees fahrenheit is converted to %.2lf degree celsius ",f,c);
opt=0;
break;
case 2:
printf(" Please enter the temperature in celsius: ");
scanf("%lf",&c);
f=CalculateFahrenheit(c);
printf("%.2lf degrees celsius is converted to %.2lf degree fahrenheit ",c,f);
opt=0;
break;
case 3:
printf(" Please enter number of kilometers: ");
scanf("%lf",&k);
m=CalculateMiles(k);
printf("%.2lf Kilometers is converted to %.2lf miles ",k,m);
opt=0;
break;
case 4:
printf(" Please enter number of miles: ");
scanf("%lf",&m);
k=CalculateKilometers(m);
printf("%.2lf miles is converted to %.2lf kilometers ",m,k);
opt=0;
break;
case 5:
printf("bye!! ");
flag=1;
opt=0;
break;
default :
break;
}
}while(flag==0);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.