Exemple #1
0
        static void Output(FahrenheitTemperature fTemp, CelsiusTemperature cTemp)
        {
            Console.WriteLine(String.Format("The current temperature in Cesuis is {0}\u00B0C", round(cTemp.measurement)));
            Console.WriteLine(String.Format("The current temperature in Fahrenheit is {0}\u00B0F", round(fTemp.measurement)));
            Console.WriteLine(@"Would you like to make another conversion? (Y/N)");
            string input = Console.ReadLine().ToUpper();

            if (input == "Y" || input == "YES")
            {
                Start();
            }
        }
        static void Main(string[] args)
        {
            float ftemp             = 32F;
            float ctemp             = 0F;
            FahrenheitTemperature c = new FahrenheitTemperature(ftemp);
            var cresult             = (CelsiusTemperature)c;

            Console.WriteLine(cresult.temp);

            Console.WriteLine("****************");

            CelsiusTemperature f = new CelsiusTemperature(ctemp);
            var fresult          = (FahrenheitTemperature)f;

            Console.WriteLine(fresult.temp);
            Console.ReadLine();
        }
Exemple #3
0
        static void Start()
        {
            Console.Write("Input a temperature followed by an F for Fahrenheit or a C for Celsius: ");
            string input = Console.ReadLine().ToUpper();
            FahrenheitTemperature fTemp;
            CelsiusTemperature    cTemp;

            switch (input[input.Length - 1])
            {
            case 'F':
                input = input.TrimEnd('F');
                if (Double.TryParse(input, out double fTempValue))
                {
                    fTemp = new FahrenheitTemperature(fTempValue);
                    cTemp = (CelsiusTemperature)fTemp;
                    Output(fTemp, cTemp);
                }
                else
                {
                    invalidInput();
                }
                break;

            case 'C':
                input = input.TrimEnd('C');
                if (Double.TryParse(input, out double cTempValue))
                {
                    cTemp = new CelsiusTemperature(cTempValue);
                    fTemp = (FahrenheitTemperature)cTemp;
                    Output(fTemp, cTemp);
                }
                else
                {
                    invalidInput();
                }
                break;

            default:
                invalidInput();
                break;
            }
        }