static void Main() { Console.WriteLine("Please select the convertor direction"); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. From Fahrenheit to Celsius."); Console.Write(":"); string selection = Console.ReadLine(); double F, C = 0; switch (selection) { case "1": Console.Write("Please enter the Celsius temperature: "); F = TemperatureConverter.CelsiusToFahrenheit(Console.ReadLine()); Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F); break; case "2": Console.Write("Please enter the Fahrenheit temperature: "); C = TemperatureConverter.FahrenheitToCelsius(Console.ReadLine()); Console.WriteLine("Temperature in Celsius: {0:F2}", C); break; default: Console.WriteLine("Please select a convertor."); break; } // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
static void Main(string[] args) { string selection = string.Empty; while (selection != "Q" && selection != "q") { Console.Write("Enter C)elsius to Fahrenheit or F)ahrenheit to Celsius or Q)uit: "); selection = Console.ReadLine(); double fahrenheit, celsius = 0; switch (selection) { case "C": case "c": Console.Write("Please enter the Celsius temperature: "); fahrenheit = TemperatureConverter.CelsiusToFahrenheit(Console.ReadLine()); Console.WriteLine($"Temperature in Fahrenheit: {fahrenheit:f2}"); break; case "F": case "f": Console.Write("Please enter the Fahrenheit temperature: "); celsius = TemperatureConverter.FahrenheitToCelsius(Console.ReadLine()); Console.WriteLine($"Temperature in Celsius: {celsius:f2}"); break; case "Q": case "q": break; default: Console.WriteLine("Please try again"); break; } } }