Question

If Else C coding program. Write a program to choose wehter to convert Celsius to Fahrenheit...

If Else C coding program. Write a program to choose wehter to convert Celsius to Fahrenheit or Fahrenheit to Celsius. If the user chooses neither of the two options, the program will exit the while loop and terminate.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

double getF(double celsius){
   return ((9.0 / 5.0) * celsius + 32);
}

double getC(double fahrenheit){
   return (5.0/9.0*(fahrenheit-32));
}

int main()
{
   double temp, end = -1;
   char ch, flush;
   while(1){
      printf("Enter the temparature or -1 to exit: ");
      scanf("%lf",&temp);
      if(temp == end){
         return;
      }
      scanf("%c",&flush);
      printf("C or F: ");
      scanf("%c",&ch);
      if(ch == 'F'){
         printf("%lf F = %lf C\n", temp, getC(temp));
      }
      else{
         printf("%lf C = %lf F\n", temp, getF(temp));
      }
   }
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
If Else C coding program. Write a program to choose wehter to convert Celsius to Fahrenheit...
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
  • Convert Celsius to Fahrenheit. (Programming Exercise 2.1) or Convert Fahrenheit to Celsius. Write a program with...

    Convert Celsius to Fahrenheit. (Programming Exercise 2.1) or Convert Fahrenheit to Celsius. Write a program with reads a Celsius degree value from the console or a Fahrenheit degree value from the console , then converts it to Fahrenheit or Celsius and displays the result. The formulas for the conversion are as follows: Fahrenheit = (9 / 5) * Celsius + 32 Celsius = (5/9) *(Fahrenheit -32) Write this program in Java please

  • 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....

  • 8.) Write a C++ program to convert temperature in degrees Fahrenheit to degrees Celsius. This is...

    8.) Write a C++ program to convert temperature in degrees Fahrenheit to degrees Celsius. This is the equation for this conversion: Celsius = 5.0/9.0 (Fahrenheit-32.0) Have your program convert and display the Celsius temperature corresponding to 98.6 degrees Fahrenheit. Your program should produce the following display (replacing the underlines with the correct values): For a Fahrenheit temperature of-_ degrees, the equivalent Celsius temperature is degrees

  • 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...

  • IN JAVA: 1. Write a program to convert 40 degrees to 94 degrees Fahrenheit to Celsius...

    IN JAVA: 1. Write a program to convert 40 degrees to 94 degrees Fahrenheit to Celsius (USE FOR LOOP) 2. Print the odd numbers from 1 to 100 (USE FOR LOOP)

  • 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...

  • Write a program in C that will convert all 12 months' average temperature from Celsius to...

    Write a program in C that will convert all 12 months' average temperature from Celsius to Fahrenheit. You need to create an array named aye jump and prompt the user to input average temperature in Celsius for all 12 months. After that, you need to develop a user temperatures from Celsius to Fahrenheit and pass the array as reference and convert all temperatures from Celsius to Fahrenheit. Next, compute the average temperature of the year and assign it to a...

  • Question 2 Write a program to generate a table of conversions from Fahrenheit to Celsius for...

    Question 2 Write a program to generate a table of conversions from Fahrenheit to Celsius for values from 0 degrees F to 100 degrees F. Print a line in the table for each 5-degree change. Use a while loop in your solution. 1) re,-(TCF)-32) x 5/9 Write a program to generate a table of conversions from Fahrenheit to Kelvin for values from 0 degrees F to 200 degrees F. Allow the user to enter the increment in degrees Fahrenheit between...

  • please solve it using c++ coding Write a C++ program that outputs a table having four...

    please solve it using c++ coding Write a C++ program that outputs a table having four columns of temperature values, ordered as follow: Celsius, Fahrenheit, Kelvin and Rankine. Use a while loop Let the Celsius temperature vary from 0.0 to 100.0 in steps of 5 °C. Convert each of these values to the other scales using the formulas given in Lab-1 (reproduced here for your convenience): 1) KELVIN CELSIUS FAHRENHEIT RAN KINE 31SOLS 2672 273 MELTS 32 a. Fahrenheit (F):...

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