How to change Celsius to Fahrenheit
I am not quite understanding I am working with Microsoft Visual basic .Net programming and I Have this so far
Sub Main()
Dim fahrenheit, celsius As Double
Console.WriteLine("Enter a value for fahrenheit tempature:")
fahrenheit = Convert.ToDouble(Console.ReadLine())
celsius = 5 / 9 * (fahrenheit - 32)
celsius = Math.Round(celsius, 1)
Console.WriteLine(fahrenheit & " F = " & celsius & " C")
Now I have to add similar lines of code to change Celsius temp to Fahrenheit now do I just repeat what I have or is there another way I am exploring to understand this.I have tried a few things but it is not working.. Can someone explain what I am doing wrong.. and I suppose to use the else if?
Sub Main()
Dim fahrenheit, celsius As Double
Console.WriteLine("Enter a value for fahrenheit tempature:")
fahrenheit = Convert.ToDouble(Console.ReadLine())
celsius = 5 / 9 * (fahrenheit - 32)
fahrenheit = celsius * 9 / 5 + 32
celsius = Math.Round(celsius, 1)
Console.WriteLine(fahrenheit &开发者_C百科amp; " F = " & celsius & " C")
End Sub
Ok this is what I have no when the black box comes run when you debug it it only states fahrenheit how can I also get it to read celsius too or do I have to just start clear and make each one as there own.
If this is a learning exercise, why not produce a function for each?
Function GetCelsiusForFahrenheit(ByVal fahrenheit as Double) As Double
Return (5/9) * (fahrenheit - 32)
End Function
Function GetFahrenheitForCelsius(ByVal celsius as Double) As Double
Return (9/5) * celsius + 32
End Function
why do you not use the "other direction formula" for this? So that would be
fahrenheit = (9 / 5 * celsius) + 32
精彩评论