Unit Converter/Program.cs
/// <summary>
/// Option 1. Prints the conversion to the screen. Uses conversion methods FahrenheitToCelsius(degrees) and CelsiusToFahrenheit(degrees)
/// </summary>
Option 1. Prints the conversion to the screen.
Option 1 . Prints the conversion to the screen .
static void GetTemp()
        {
            char selection;
            bool endFlag;
            double degrees;
            string degreesString;
            do
            {
                endFlag = true;
                Console.WriteLine("\nTemperature:\n" +
                  "[1]Fahrenheit to Celsius\n" +
                  "[2]Celsius to Fahrenheit\n");
                Console.Write("Selection: ");
                selection = Console.ReadKey().KeyChar;
                switch (selection)
                {
                    case '1':
                        {
                            Console.Write("\nEnter degrees in Fahrenheit: ");
                            degreesString = Console.ReadLine();
                            while (double.TryParse(degreesString, out degrees) == false)
                            {
                                Console.WriteLine("\nPlease enter valid degrees: ");
                                degreesString = Console.ReadLine();
                            }
                            degrees = double.Parse(degreesString);
                            Console.WriteLine("\n{0:F2} degrees Fahrenheit equals {1:F2} degrees Celsius", degrees, FahrenheitToCelsius(degrees));
                            break;
                        }
                    case '2':
                        {
                            Console.Write("\nEnter degrees in Celsius: ");
                            degreesString = Console.ReadLine();
                            while (double.TryParse(degreesString, out degrees) == false)
                            {
                                Console.WriteLine("\nPlease enter valid degrees: ");
                                degreesString = Console.ReadLine();
                            }
                            degrees = double.Parse(degreesString);
                            Console.WriteLine("\n{0:F2} degrees Celsius equals {1:F2} degrees Fahrenheit", degrees, CelsiusToFahrenheit(degrees));
                            break;
                        }
                    default:
                        {
                            endFlag = false;
                            break;
                        }
                }
            } while (endFlag == false);
        }
static void GetTemp ( ) { char selection ; bool endFlag ; double degrees ; string degreesString ; do { endFlag = true ; Console . WriteLine ( " \n \n " + " \n " + " \n " ) ; Console . Write ( " " ) ; selection = Console . ReadKey ( ) . KeyChar ; switch ( selection ) { case ' ' : { Console . Write ( " \n " ) ; degreesString = Console . ReadLine ( ) ; while ( double . TryParse ( degreesString , out degrees ) == false ) { Console . WriteLine ( " \n " ) ; degreesString = Console . ReadLine ( ) ; } degrees = double . Parse ( degreesString ) ; Console . WriteLine ( " \n " , degrees , FahrenheitToCelsius ( degrees ) ) ; break ; } case ' ' : { Console . Write ( " \n " ) ; degreesString = Console . ReadLine ( ) ; while ( double . TryParse ( degreesString , out degrees ) == false ) { Console . WriteLine ( " \n " ) ; degreesString = Console . ReadLine ( ) ; } degrees = double . Parse ( degreesString ) ; Console . WriteLine ( " \n " , degrees , CelsiusToFahrenheit ( degrees ) ) ; break ; } default : { endFlag = false ; break ; } } } while ( endFlag == false ) ; }
Option 1.
Option 1 .