Aplikasi dan Kode Program Konversi Suhu Menggunakan Bahasa C#



Suhu atau biasa disebut juga dengan temperatur merupakan derajat panas atau dingin dari suatu benda. Suhu suatu benda tergantung pada energi kinetik (gerak) dari molekul-molekul benda yang ada di dalamnya.

Di bawah ini adalah sebuah Listing Program untuk Konversi Suhu Menggunakan Bahasa C#. 

 int pilihan;
            float c, f, k, r;
            do
            {
                Console.Clear();
                Console.WriteLine("Menu");
                for (int i = 0; i < 30; i++)
                {
                    Console.Write("=");
                }
                Console.WriteLine();
                Console.Write("1.Konversi suhu Celcius  \n2.Konversi suhu Reamur  \n3.Konversi suhu Fahrenheit \n4.Konversi suhu Kelvin \n0.Keluar Program \nPilihan => ");
                pilihan = int.Parse(Console.ReadLine());
                if (pilihan == 1)
                {
                    Console.Clear();
                    Console.Write("Input Suhu Celcius = ");
                    c = float.Parse(Console.ReadLine());
                    f = c * ((float)1.8) + 32;
                    k = c + ((float)273.15);
                    r = c * ((float)0.8);
                    Console.WriteLine("Suhu Fahrenheit = {0}", f);
                    Console.WriteLine("Suhu Kelvin     = {0}", k);
                    Console.WriteLine("Suhu Reamur     = {0}", r);
                    Console.ReadKey();
                }
                else if (pilihan == 2)
                {
                    Console.Clear();
                    Console.Write("Input Suhu Reamur = ");
                    r = float.Parse(Console.ReadLine());
                    c = r / (float)0.8;
                    f = r * (float)2.25 + 32;
                    k = r / (float)0.8 + (float)273.15;
                    Console.WriteLine("Suhu Fahrenheit = {0}", f);
                    Console.WriteLine("Suhu Kelvin     = {0}", k);
                    Console.WriteLine("Suhu Celcius    = {0}", c);
                    Console.ReadKey();
                }
                else if (pilihan == 3)
                {
                    Console.Clear();
                    Console.Write("Input Suhu Fahrenheit = ");
                    f = float.Parse(Console.ReadLine());
                    c = (f - 32) / (float)1.8;
                    r = (f - 32) / (float)2.25;
                    k = (f + (float)459.67) / (float)1.8;
                    Console.WriteLine("Suhu Reamur     = {0}", r);
                    Console.WriteLine("Suhu Kelvin     = {0}", k);
                    Console.WriteLine("Suhu Celcius    = {0}", c);
                    Console.ReadKey();


                }
                else if (pilihan == 4)
                {
                    Console.Clear();
                    Console.Write("Input Suhu Kelvin = ");
                    k = float.Parse(Console.ReadLine());
                    c = k - (float)273.15;
                    r = (k - (float)273.15) * (float)0.8;
                    f = k * (float)1.8 - (float)459.67;
                    Console.WriteLine("Suhu Reamur     = {0}", r);
                    Console.WriteLine("Suhu Fahrenheit = {0}", f);
                    Console.WriteLine("Suhu Celcius    = {0}", c);
                    Console.ReadKey();


                }
            } while (pilihan != 0);


Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 komentar:

Post a Comment