DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

VB.NET/C# program to convert Fahrenheit to Celsius and Celsius to Fahrenheit

By Ashok Nalam on 28 Jun 2013 | Category: VB.NET | Tagged: C# number .NET conversion difference 
This program(VB.NET/C# versions) converts temperature from Fahrenheit to Celsius and Celsius to Fahrenheit.
  Discuss Add Comment   |  
Add rating Rate this resource   

Fahrenheit or Celsius (centigrade) is a scale and unit of measurement for temperature. In United States, Fahrenheit is accepted standard for non-scientific usage and All other countries uses the Celsius as primary scale to measure temperature. In this program we will see how to convert Fahrenheit to Celsius and Celsius to Fahrenheit using standard formula.

Formula:

 °F = °C  x  9/5 + 32

 °C = (°F  -  32)  x  5/9

Examples: 

100°C = 212°F ( 100°C multiplied by 9/5 +32 = 212°F )

50°F = 10°C ( (50°F - 32) multiplied by 5/9 = 10°C )

VB.NET Program:

Namespace DotNetMirror
    Class TempConversion
        Shared Sub Main()
            Console.WriteLine("/***** Fahrenheit to Celsius & Celsius to Fahrenheit Conversion Program *****/")
            Dim temperatue As Double
            Dim result As Double
            ' Fahrenheit to Celsius
            Console.WriteLine("Enter temperature in Fahrenheit(°F)")
            temperatue = Convert.ToDouble(Console.ReadLine())
            result = ConvertF2C(temperatue)
            Console.WriteLine("Converted temperature in Celsius = " & result & "°C")
            '  Celsius to Fahrenheit
            Console.WriteLine("Enter temperature in Celsius(°C)")
            temperatue = Convert.ToDouble(Console.ReadLine())
            result = ConvertC2F(temperatue)
            Console.WriteLine("Converted temperature in Fahrenheit = " & result & "°F")
            Console.ReadLine()
        End Sub
        Shared Function ConvertC2F(c As Double) As Double
            Return c * 9 / 5 + 32
        End Function
        Shared Function ConvertF2C(f As Double) As Double
            Return (f - 32) * 5 / 9
        End Function
    End Class
End Namespace

Output:


C#.NET Program: 

FYI. Same program has been converted to C# version.

namespace DotNetMirror
{
    class TempConversion
    {
        static void Main()
        {
            Console.WriteLine("/***** Fahrenheit to Celsius & Celsius to Fahrenheit Conversion Program *****/");
            double temperatue;
            double result;
            // Fahrenheit to Celsius
            Console.WriteLine("Enter temperature in Fahrenheit(°F)");
            temperatue = Convert.ToDouble(Console.ReadLine());
            result = ConvertF2C(temperatue);
            Console.WriteLine("Converted temperature in Celsius = " + result + "°C");
            //  Celsius to Fahrenheit
            Console.WriteLine("Enter temperature in Celsius(°C)");
            temperatue = Convert.ToDouble(Console.ReadLine());
            result = ConvertC2F(temperatue);
            Console.WriteLine("Converted temperature in Fahrenheit = " + result + "°F");
            Console.ReadLine();
        }
        public static double ConvertC2F(double c)
        {
            return c * 9 / 5 + 32;
        }
        public static double ConvertF2C(double f)
        {
            return (f - 32) * 5 / 9 ;
        }
    }
}
  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 9526  (Professional)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (0)
No comments found, click here to add comment.
 
cheap jordans|wholesale air max|wholesale jordans|wholesale jewelry|wholesale jerseys