Social Icons

Thursday, 13 March 2014

C# Program of temperature conversion


using System;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
         {
            while (true)
             {
                int n;
                 //main menu
                 Console.WriteLine("\n\n Press 1: Fahrenheit TO Celsius ");
                 Console.WriteLine(" Press 2: Celsius TO Fahrenheit");
                 Console.WriteLine(" Press 3: for exit");
                 Console.Write("\n\n Enter your choice : ");
                 n = Int32.Parse(Console.ReadLine());
                 switch (n)
                 {
                     case 1:                 //Fahrenheit to Celsius
                         {
                             double f, c;
                             Console.Write(" Enter temperature in Fahrenheit: ");
                             f = double.Parse(Console.ReadLine());
                             c = (f - 32) * 5 / 9;
                             Console.WriteLine("\n\t"+ f + " degree Fahrenheit= " + c + " degree Celsius ");
                             break;
                         }
 
                    case 2:             //Celsius to Fahrenheit
                         {
                             double f, c;
                             Console.Write(" Enter temperature in Celsius : ");
                             c = double.Parse(Console.ReadLine());
                             f = c * 9 / 5 + 32;
                             Console.WriteLine("\n\t"+ c + " degree Celsius = " + f + " degree Fahrenheit");
                             break;
                         }
                     case 3:         //Exit from program
                         return;


                    default:
                         Console.WriteLine("\n Wrong choice...");
                         break;

               }
            }
        }
     }
}
                                                                 Output


No comments:

Post a Comment