Question

Using Functions: Conversion Program: Write a program that perform conversions that we use often. Program should...

Using Functions:

Conversion Program: Write a program that perform conversions that we use often. Program should display the following menu

           

                                                Welcome to the Conversion Program

                                                ===============================

Fahrenheit to Celsius

Miles to kilometers

Liters to Gallons

Exit from the program

You should implement this program using functions and your program need to have following functions

void displayMenu()

double fahrenheitToCilsuis(double fTemp)

double milesToKilometers(double miles)

double litersToGallons(doube liters)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

//displaying menu function

void displayMenu()

{

printf("\n\t\t\tWelcome to the conversion program\n\n");

printf("--------------------------------------------------------------------\n");

printf("1.Fahrenheit to Celsius\n2.Miles to Kilometers\n3.Liters to Gallons\n4.Exit\n");

}

//fahrenhiet to cilisuis converstion

double fahrenheitToCilsuis(double fTemp)

{

//Forumula to convert from Fahrenhiet to Celsius

//subtract 32 from the input and then multiply with 5 then divide with 9

return (fTemp-32)*5/9;

}

//miles to killometers conversion

double milesToKilometers(double miles)

{

//one mile is equal to 1.6 kilometers

return miles*1.6;

}

//liters to gallons convetsion

double litersToGallons(double liters)

{

//one liter is equal to 0.26417 gallons

return (liters*0.26417);

}

//main function

int main()

{

int option;

double fTemp,celsius,miles,km,liters,gallons;

//loop will iterate until user exit

do{

displayMenu();//calling displayMenu function

scanf("%d",&option);

switch(option)

{

//temperature conversion

case 1:

printf("Enter temperature in Fahrenhiet\n");

scanf("%ld",&fTemp);

celsius=fahrenheitToCilsuis(fTemp);

printf("Fahrenhiet = %ld --- Celsius = %ld\n",fTemp,celsius);

break;

//distance conversion

case 2:

printf("Enter distance in miles\n");

scanf("%ld",&miles);

km=milesToKilometers(miles);

printf("miles = %ld --- Kilometers = %ld\n",miles,km);

break;

//volume conversion

case 3:

printf("Enter volume in liters\n");

scanf("%ld",&liters);

gallons=litersToGallons(liters);

printf("liters = %ld --- Gallons = %ld\n",liters,gallons);

break;

//exit from the program

case 4:

exit(0);

}

}while(1);

}

Add a comment
Know the answer?
Add Answer to:
Using Functions: Conversion Program: Write a program that perform conversions that we use often. Program should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in C++ that gives the temperature of earth at a depth. It must...

    Write a program in C++ that gives the temperature of earth at a depth. It must be in C++ and follow the information below: Problem description Write a program to take a depth in kilometers inside the earth as input data; calculate and display the temperature at this depth in both degrees Celsius and degree Fahrenheit. The formulas are: Celsius temperature at depth in km: celsius = 10 x depth(km) + 20 Convert celsius to fahrenheit: fahrenheit = 1.8 x...

  • For this portion of the lab, you will reuse the program you wrote before That means...

    For this portion of the lab, you will reuse the program you wrote before That means you will open the lab you wrote in the previous assignment and change it. You should NOT start from scratch. Also, all the requirements/prohibitions from the previous lab MUST also be included /omitted from this lab. Redesign the solution in the following manner: 1. All the functions used are value-returning functions. 2. Put the functions in an external module and let the main program...

  • Write python program using IDLE Write a full program that asks the user to enter his/her...

    Write python program using IDLE Write a full program that asks the user to enter his/her name then repeatedly ask to enter the temperature in Fahrenheit and convert it to Celsius, the program should then prompt the user if he/she wants to continue or exit the program. The formula for the conversion is: °C = (°F - 32) x 5/9 The program should use a function for the conversion. An Example of a sample run should appear on the screen...

  • Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The...

    Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...

  • FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice...

    FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom functionc_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a...

  • Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The...

    Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...

  • A liter is 0.264179 gallons. Write a program that will read in the number of liters...

    A liter is 0.264179 gallons. Write a program that will read in the number of liters of gasoline consumed by the user's car and the number of miles per gallon the car delivered. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the number of miles per gallon. Your program should use a globally defined constant for the number of liters per gallon. After doing this... Modify your...

  • java programming Problem 2) Convert Kilometers to Miles Write a JavaFX program using JavaFX Menu for...

    java programming Problem 2) Convert Kilometers to Miles Write a JavaFX program using JavaFX Menu for to solve the following problem about converting between Kilometers to Miles. Sample Run is shown below You are asked to implement only the menu item under Formulas which reads as"KM to Mile". Choosing this menu item will display the following input box: Input Enter Kilometers Value OK Cancel The result will be displayed in a TextArea as shown below: JavaF× Menu Example " File...

  • Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...

    Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....

  • Q2: Write a menu-driven C program using switch-case to calculate the following: 1. Area of circle...

    Q2: Write a menu-driven C program using switch-case to calculate the following: 1. Area of circle 2. Area of square 3. Area of rectangle The program should use the following functions properly: void displayMenu() //a function that will display the menu options to the user int getChoice() //a function that will input the user choice and returns it float calculate(int choice) //a function that reads the required inputs based on the user choice, and returns the area of the shape...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT