7. Open the Temperature Solution (Temperature Solution.sln) file contained in th
ID: 3663841 • Letter: 7
Question
7. Open the Temperature Solution (Temperature Solution.sln) file contained in the ClearlyVB2012Chap12Temperature Solution folder. The Calculate button’s Click event procedure should allow the user to enter zero or more temperatures. It then should display the number of temperatures entered and the average temperature. Include one decimal place in the average temperature. Code the procedure. Save the solution and then start and test the application. Close the Code Editor window and then close the solution.
Explanation / Answer
'Contains the student grade.
Dim Temprature As Integer
'Contains the sum of temprature that are entered.
Dim SumOfTemprature As Integer
'Counter for the number of items.
Dim NumberOfTemprature integer
'The average value of temprature.
Dim Average As Double
'The current user input.
Dim Input As String = ""
'Repeat the loop until the input is End.
Do Until Input = "End"
'Ask the user to enter a temprature.
Console.WriteLine("Enter a temprature:")
Input = Console.ReadLine()
'Verify the input
If Input = "End" Then
'If the input is End, compute the average temprature.
Average = SumOfTemprature / NumberOfTemprature
Console.WriteLine("The average temprature is {0}", Average.ToString())
Exit Sub
Else
'Compute the temperature and total if the input is not End.
Temperature = Convert.ToInt32(Input)
SumOfTemperature += Temperature
NumberOfTemperature += 1
End If
Loop
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.