We appreciate your visit to Write a program that allows the user to convert a temperature given in degrees from either Celsius to Fahrenheit or Fahrenheit to Celsius Use the. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!

Write a program that allows the user to convert a temperature given in degrees from either Celsius to Fahrenheit or Fahrenheit to Celsius. Use the following formulas:

\[ \text{Degrees}_C = \frac{5(\text{Degrees}_F - 32)}{9} \]
\[ \text{Degrees}_F = \left( \frac{9(\text{Degrees}_C)}{5} \right) + 32 \]

1. Prompt the user to enter a temperature and either a "C" or "c" for Celsius or an "F" or "f" for Fahrenheit.
2. Convert the temperature to Fahrenheit if Celsius is entered, or to Celsius if Fahrenheit is entered.
3. Display the result in a readable format.
4. If anything other than "C", "c", "F", or "f" is entered, print an error message and stop.

Answer :

Answer:

import java.util.Scanner;

public class num6 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter the temperature");

double temp = in.nextDouble();

System.out.println("Enter C to convert to celsius or F for fahrenheit");

String con = in.next();

if (con.equalsIgnoreCase("C")) {

double Degrees_C = 5 * (temp - 32) / 9;

System.out.println("The temperature of " + temp + "F in Celcius is" +

" " + Degrees_C);

} else if (con.equalsIgnoreCase("F")) {

//Degrees_F = (9(Degrees_C)/5) + 32)

double Degrees_F = (9 * (temp) / 5) + 32;

System.out.println("The temperature of " + temp + " celcius in Farenheit is" +

" " + Degrees_F);

} else {

System.out.println("Invalid value for conversion");

}

}

}

Explanation:

Use Scanner Class to prompt and receive user input

Use string method equalsIgnoreCase in an if statement to test the conversion to degrees celcius or farenheit

evaluate and output the values based on the equation given in the question

Thanks for taking the time to read Write a program that allows the user to convert a temperature given in degrees from either Celsius to Fahrenheit or Fahrenheit to Celsius Use the. We hope the insights shared have been valuable and enhanced your understanding of the topic. Don�t hesitate to browse our website for more informative and engaging content!

Rewritten by : Barada

The program is a temperature converter which converts temperature values based on the unit and value inputted by the user. The program is written in python 3 thus ;

unit = input('your temperature unit : ')

#takes unit input in Celcius (C) or Fahrenheit (F)

unit = unit.lower()

#changes the input to lower case

value = eval(input('temperature value : '))

#takes temperature value input

def converter(value):

#initialize a function named converter which takes in the inputted value as parameter

if(unit == 'c'):

#Checkthe unit entered by user.

deg_c = 5*(value - 32)/9

return deg_c

else:

deg_f = (9*(value)/5)+ 32

return deg_f

#returns the converted temperature values.

print(converter(value))

A sample run of the program is attached.

Learn more : https://brainly.com/question/19539086