Write a C++ program that will do a Celsius to Fahrenheit conversion for the temperature 55 degrees Celsius to its Fahrenheit equivalent and Fahrenheit to Celsius conversion.

Answer :

To convert temperatures between Celsius and Fahrenheit using a C++ program, you can follow these steps. We'll handle both the conversion of 55 degrees Celsius to Fahrenheit and a general conversion from Fahrenheit to Celsius.

Celsius to Fahrenheit

The formula to convert Celsius to Fahrenheit is:

[tex]F = C \times \frac{9}{5} + 32[/tex]

Using this formula, we convert 55 degrees Celsius:

[tex]F = 55 \times \frac{9}{5} + 32 = 131[/tex]

Fahrenheit to Celsius

The formula to convert Fahrenheit to Celsius is:

[tex]C = (F - 32) \times \frac{5}{9}[/tex]

For this part, you could convert any Fahrenheit temperature to Celsius. For example, converting 131 Fahrenheit back to Celsius:

[tex]C = (131 - 32) \times \frac{5}{9} = 55[/tex]

C++ Program

#include

int main() {
double celsius = 55;
double fahrenheit = celsius * 9.0 / 5.0 + 32;
std::cout << celsius << " Celsius is equal to " << fahrenheit << " Fahrenheit." << std::endl;

// Convert Fahrenheit back to Celsius
double fahrenheitInput = 131; // Let's use the result from above
double celsiusConverted = (fahrenheitInput - 32) * 5.0 / 9.0;
std::cout << fahrenheitInput << " Fahrenheit is equal to " << celsiusConverted << " Celsius." << std::endl;

return 0;
}

This code outputs:

  • "55 Celsius is equal to 131 Fahrenheit."
  • "131 Fahrenheit is equal to 55 Celsius."

The program demonstrates both conversions, using arithmetic expressions to calculate the results based on the conversion formulas. The output confirms both forward and reverse conversion, illustrating the accuracy of the transformations.