static void Main(string[] args) { // We ask for user input, choose which conversion you want // if the user press 1 we are doing conversion from celsius to fahrenheit // if user press 2, we are doing conversion from fahrenheit to celsius // and base of user input we are calling the corresonding static method // for conversion and just print the conversion on the console.. // TODO : For excercise here you can implement validation, what if user enters other value // TODO : different from 1 and 2 ? We need to validate that input and return message that // TODO : input is invalid... Console.WriteLine("Select the convertor direction"); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. From Fahrenheit to Celsius."); string selection = Console.ReadLine(); double F, C = 0; switch (selection) { case "1": Console.Write("Enter the Celsius temperature: "); F = TemperatureConvertor.CelsiusToFarenheit(Console.ReadLine()); Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F); break; case "2": Console.Write("Enter the Farenheit temperature: "); C = TemperatureConvertor.FarenheitToCelsius(Console.ReadLine()); Console.WriteLine("Temperature in Celsius: {0:F2}", C); break; } }
static void Main(string[] args) { Console.WriteLine("Select the convertor direction"); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. From Fahrenheit to Celsius."); string selection = Console.ReadLine(); switch (selection) { case "1": { Console.Write("Enter the Celsius temperature: "); var fahrenheit = TemperatureConvertor.CelsiusToFahrenheit(Console.ReadLine()); Console.WriteLine("Temperature in Fahrenheit: {0:F2}", fahrenheit); break; } case "2": { Console.Write("Enter the Fahrenheit temperature: "); var celsius = TemperatureConvertor.FahrenheitToCelsius(Console.ReadLine()); Console.WriteLine("Temperature in Celsius: {0:F2}", celsius); break; } } }