Exemplo n.º 1
0
        private void btn_OK_Click(object sender, EventArgs e)
        {
            char fromTemp = 'F';
            char toTemp   = 'F';

            if (radio_F.Checked)
            {
                fromTemp = 'F';
            }
            if (radio_C.Checked)
            {
                fromTemp = 'C';
            }
            if (radio_K.Checked)
            {
                fromTemp = 'K';
            }
            if (radio_toF.Checked)
            {
                toTemp = 'F';
            }
            if (radio_toC.Checked)
            {
                toTemp = 'C';
            }
            if (radio_toK.Checked)
            {
                toTemp = 'K';
            }

            Calc = new ConversionCalculator(int.Parse(txt_temp.Text), fromTemp);

            switch (toTemp)
            {
            case 'C':
                label_answer.Text = Calc.toCelsius().ToString();
                break;

            case 'F':
                label_answer.Text = Calc.toFahrenheight().ToString();
                break;

            case 'K':
                label_answer.Text = Calc.toKelvin().ToString();
                break;
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            char fromScale;
            char toScale;

            while (true)
            {
                Console.WriteLine("What temperature do you want to convert? (int number please)");

                int fromTemp = int.Parse(Console.ReadLine());
                Console.WriteLine("What temperature scale is " + fromTemp + " in? (C F or K)");
                fromScale = Console.ReadLine()[0];



                Console.WriteLine("What temperature do you want to convert to? (C F or K)");
                toScale = Console.ReadLine()[0];

                ConversionCalculator calculator = new ConversionCalculator(fromTemp, fromScale);

                switch (toScale)
                {
                case 'C':
                    Console.WriteLine(fromTemp + " in Celsius is " + calculator.toCelsius());
                    break;

                case 'F':
                    Console.WriteLine(fromTemp + " in Fahrenheight is " + calculator.toFahrenheight());
                    break;

                case 'K':
                    Console.WriteLine(fromTemp + " in Kelvin is " + calculator.toKelvin());
                    break;
                }
            }
        }