Exemple #1
0
    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         = 0,
               C         = -1
                           /* updated */
        ;

        switch (selection)
        {
        case "1":
            Console.Write("Please enter the Celsius temperature: ");
            Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F);
            break;

        case "2":
            Console.Write("Please enter the Fahrenheit temperature: ");
            C = TemperatureConverter.FahrenheitToCelsiu(Console.ReadLine());
            Console.WriteLine("Temperature in Celsius: {0:F2}", C);
            break;

        default:
            Console.WriteLine("Please select a convertor.");
            break;
        }
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
Exemple #2
0
    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.FahrenheitToCelsiu(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();
    }