Temperature Conversion from Fahrenheit to Celsius

This C# snippet prompts the user to input a temperature in Fahrenheit, converts it to Celsius using the formula (°F - 32) x 5/9, and outputs the result rounded to two decimal places.
 avatar
unknown
csharp
2 months ago
324 B
5
Indexable
//(°F - 32) x 5/9 =°C
Console.WriteLine("Podaj temperaturę w stopniach Fahrenheita: ");
float stopnieFahrenheita = float.Parse(Console.ReadLine()!);

float stopnieCelcjusza = (stopnieFahrenheita - 32) * 5f / 9f;

Console.WriteLine($"Temperatura w stopniach celcjusza wynosi: {Math.Round(stopnieCelcjusza, 2)}");
Editor is loading...
Leave a Comment