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

Problem 2 Write a function to convert a temperature value from Celsius to Fahren

ID: 3747744 • Letter: P

Question

Problem 2 Write a function to convert a temperature value from Celsius to Fahrenheit and print the emperature in Fahrenheit using the format of the example. Hint: the formula for converting Celsius(C) to Fahrenheit (F): F C(9/5) 32 . Your function name MUST be named celsiusToFahrenheit . Your function should accept only one input argument: temperature in Celsius, as a integer Your function should not return any value Your function should print the resulting temperature Fahrenheit value, with a two dig precision, in the following format: . For example, given input temperature as 38, it should print: The temperature of 38 in fahrenheit is 100.40

Explanation / Answer

Hello there, here is the required function definition for you. Since you have not mentioned the language, I’m attaching the function code in C++, C, Java and Python languages. Feel free to drop a comment if you have any doubts, and don’t forget to mention the language next time you post a question, or it may delay the time to get your question answered. Thanks

in C++

//function which converts a temperature in celsius to fahrenheit and prints it

void celsiusToFahrenheit(int celsius){

              //converting celsius to fahrenheit, applying the formula

              double fahrenheit=celsius*(9.0/5.0)+32;

              //displaying the temperature with a fixed precision of 2 digits after decimal point

              cout<<"The temperature of "<<celsius<<" in fahrenheit is "<<setprecision(2)<<fixed<<fahrenheit<<endl;

              //you should include iomanip.h header file for this

} //end of function

//in C

//function which converts a temperature in celsius to fahrenheit and prints it

void celsiusToFahrenheit(int celsius){

              //converting celsius to fahrenheit, applying the formula

              double fahrenheit=celsius*(9.0/5.0)+32;

              //displaying the temperature with a fixed precision of 2 digits after decimal point

              printf("The temperature of %d in fahrenheit is %.2f ",celsius,fahrenheit);

}//end of function

In Java

//function which converts a temperature in celsius to fahrenheit and prints it

void celsiusToFahrenheit(int celsius){

              //converting celsius to fahrenheit, applying the formula

              double fahrenheit=celsius*(9.0/5.0)+32;

              //displaying the temperature with a fixed precision of 2 digits after decimal point

              System.out.printf("The temperature of %d in fahrenheit is %.2f ",celsius,fahrenheit);

}//end of function

In Python

def celsiusToFahrenheit(celsius):

    fahrenheit=celsius*(9.0/5.0)+32;

    print('The temperature of {:d} in Fahrenheit is {:.2f}'.format(celsius,fahrenheit))

Thanks!

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