Monday, March 17, 2014

Loop Structures (While)_Ex_4_Wk (5)_Feb 4

Question 4:  Convert temperature Fahrenheit (F) to Celsius (C).
Vary Fahrenheit from 32 to 212, Compute Celsius and display both.
Formula: C = 5 * (F-32)/9 (use float or double)

static void Main(string[] args)
        {
            double F = 32;
            while (F >= 32 && F <= 200)
            {
                double C = 5 * (F - 32) / 9;
                Console.WriteLine("Fahrenheit: {0} -- {1:f1} Celsius", F, C);
                F++;
            }
            Console.ReadKey();
        }

No comments:

Post a Comment