Top

.NET Temprature Converter C/F


.NET Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  0.0 (of 0 scores)
Date Added  Sep 28, 2009
Last Updated  Sep 28, 2009
Tags  .net  44  cf  converter  jonesy  jonesy44  temprature 

Introduction

A Console Application to convert between Celsius and Fahrenheit. Alternatively, you could use the c2f() and f2c() functions for other purposes

Grab the Code

Module TempratureConverter
    ' Temprature converter. Celsius/Fahrenheit
    ' Jonesy44
    ' 28 Sept 09
 
    ' declare variables
    Dim x As Double, con_type As String   ' 0=c2f,1=f2c conversion
 
    Sub Main()
        ' Main console application
        Console.WriteLine("Temprature Converter (Celsius/Fahrenheit) by Jonesy44")
        Go()
    End Sub
 
    Sub Go()
        Console.WriteLine(vbCrLf & vbCrLf & "Would you like to convert to celsius[c] or to Fahrenheit[f]? [c/f]: ") : con_type = Console.ReadLine
        Console.WriteLine("Enter the value to convert: ") : x = Console.ReadLine
        If con_type = "f" Then : c2f(x)
        ElseIf con_type = "c" Then : f2c(x)
        End If
        GoAgain()
    End Sub
 
    Sub GoAgain()
        Console.Write(vbCrLf & "Another Conversion? [y/n]: ")
        If Console.ReadLine = "y" Then : Go()
        Else : End
        End If
    End Sub
 
    Sub c2f(ByRef val As Double)
        Console.Write(val & "°C is " & Math.Round(((9 * val) + 160) / 5, 2) & "°F")
    End Sub
    Sub f2c(ByRef val As Double)
        Console.Write(val & "°F is " & Math.Round(5 * (val - 32) / 9, 2) & "°C")
    End Sub
 
End Module

Comments

  (0)  RSS

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom