Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help for Section 6.1 Exercise 23 I have written the following code: Priva

ID: 3881750 • Letter: P

Question

Please help for Section 6.1 Exercise 23 I have written the following code:

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnConversion.Click

Dim celsius As Double = 10

Dim fahrenheit As Double

lstDisplay.Items.Add("Celsius Fahrenhiet")

lstDisplay.Items.Add("-------------------------------------------")

Do While celsius <= 95

lstDisplay.Items.Add(" " & celsius & " " & fahrenheit)

celsius += 5

Loop

End Sub

Function fahrenheit(sender As Celsius, e As Double) As Double

Return CDbl(fahrenheit = (9 / 5) * 10 + 32)

End Function

End Class

when I run the program i get the celsius part of 10 to 95 but get 0 on the fahrenheit side. Please advise where I am making my mistake please.

Explanation / Answer

Function fahrenheit(sender As Celsius, e As Double) As Double

Return CDbl(fahrenheit = (9.0 / 5.0) * 10.0 + 32.0)

End Function

use double values for calculating fahrenheit. Integer division will result in truncation of decimal part.

Also the function name and variable name fahrenheit is same.

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnConversion.Click

Dim celsius As Double = 10

Dim fahrenheit As Double

lstDisplay.Items.Add("Celsius Fahrenhiet")

lstDisplay.Items.Add("-------------------------------------------")

Do While celsius <= 95

fahrenheit = Convert(celsius)

lstDisplay.Items.Add(" " & celsius & " " & fahrenheit)

celsius += 5

Loop

End Sub

Function Convert(ByVal celsius as Double) As Double

Return CDbl(fahrenheit = (9 / 5) * celsius + 32)

End Function

End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote