Vb.net 假设有5个记录,每个记录包含2个温度
假设有5个记录,每个记录包含温度值。每个记录上的第一个温度值表示来自气象站的高温,每个记录上的第二个温度值表示来自气象站的低温,将这些温度输入表TEMP 5,2,表1列中的5个站的高温,以及表第2列中5个站点的低温。读取所有温度后,查找并输出5个气象站的平均高温和平均低温 我有一个我在VB.NET中编写的代码,但它没有通过。这是密码Vb.net 假设有5个记录,每个记录包含2个温度,vb.net,Vb.net,假设有5个记录,每个记录包含温度值。每个记录上的第一个温度值表示来自气象站的高温,每个记录上的第二个温度值表示来自气象站的低温,将这些温度输入表TEMP 5,2,表1列中的5个站的高温,以及表第2列中5个站点的低温。读取所有温度后,查找并输出5个气象站的平均高温和平均低温 我有一个我在VB.NET中编写的代码,但它没有通过。这是密码 Module Module1 Dim TEMP(5, 2) As Integer Dim count As Integer Dim AVGHIGH
Module Module1
Dim TEMP(5, 2) As Integer
Dim count As Integer
Dim AVGHIGH As Integer
Dim AVGLOW As Integer
Dim i As Integer = 5
Dim high As Integer
Dim stations As Integer = 5
Dim low As Integer
Dim Totalhigh As Integer
Dim Totallow As Integer
Sub Main()
Call InputArray()
Call ComputeandOutputAverageHightempandLowtemp()
Call OutputArray()
Console.WriteLine("Please Press Enter")
Console.ReadLine()
End Sub
Sub InputArray()
stations = 0
Console.WriteLine("Enter{0} temperatures, one per line ", i)
Console.ReadLine()
TEMP(i, 2) = "High Temperature"
TEMP(i, 1) = Console.ReadLine()
TEMP(i, 2) = "Low Temperature"
TEMP(i, 2) = Console.ReadLine()
Do While stations <= i
stations = stations + 1
Loop
End Sub
Sub ComputeandOutputAverageHightempandLowtemp()
high = TEMP(i, 1)
low = TEMP(i, 2)
stations = 1
Totalhigh = 0
Totallow = 0
Do While stations <= 5
stations = stations + 1
If high > low Then
Totalhigh = 1 + TEMP(i, 1)
AVGHIGH = Totalhigh / stations
End If
Totallow = 1 + TEMP(i, 2)
AVGLOW = Totallow / stations
Loop
Console.WriteLine("High: " & Totalhigh)
Console.WriteLine("Low: " & Totallow)
Console.WriteLine("average high temperature: " & AVGHIGH)
End Sub
Sub OutputArray()
stations = 0
Console.WriteLine()
Console.WriteLine("The number in the list are: ")
Do While (stations <= 5)
stations = stations + 1
Console.WriteLine(TEMP(i, 1) & "")
Console.WriteLine(TEMP(i, 2) & "")
Loop
End Sub
End Module
模块1
Dim Temp(5, 2)
Dim HTemp As String
Dim LTemp As String
Dim TotHTemp As Integer
Dim TotLTemp As Integer
Dim AvgHTemp As Integer
Dim AvgLTemp As Integer
Dim Record As Integer
Dim Row As Integer
Dim TotRow As Integer
Dim Accum As Integer
Dim Count As Integer
Sub Main() 'Overall (A000)
Console.Write("Please Enter the total number of Stations that you want to process( High Temp and Low Temp: ")
Record = Console.ReadLine()
TotRow = Record
Row = TotRow - 1
Do While Row >= 0
Console.Write("Please Enter high Temperature: ")
HTemp = Console.ReadLine()
Console.Write("Please Enter Low Temperature: ")
LTemp = Console.ReadLine()
TotHTemp = TotHTemp + HTemp
TotLTemp = TotLTemp + LTemp
Call Input()
Loop
Call comput()
Call Output()
Console.ReadLine()
End Sub
Sub Input() '(B000)
Temp(Row, 0) = HTemp
Temp(Row, 1) = LTemp
Row = Row - 1
End Sub
Sub comput() '(B010)
AvgHTemp = TotHTemp / TotRow
AvgLTemp = TotLTemp / TotRow
End Sub
Sub Output() '(B020)
Console.WriteLine() ' for spacing
Dim format As String = "{0,-25}{1,-25}{2}"
Console.WriteLine(format, "Record", "High Temp", "Low Temp")
Accum = 1
Count = Accum
Row = 0
Do While Row < TotRow
Console.WriteLine(format, Count, Temp(Row, 0), Temp(Row, 1))
Call Counter()
Row = Row + 1
Loop
Console.WriteLine() ' for Space
Console.WriteLine(" Avg of high Temperatues =: " & AvgHTemp)
Console.WriteLine(" Avg of Low temperatures =: " & AvgLTemp)
End Sub
Sub Counter() '(C000)
Accum = Accum + 1
Count = Accum
End Sub
结束模块您所说的“程序无法通过”是什么意思。您是否接收到错误或什么都没有发生?在InputArray子系统中,您有一个do-while循环,在执行上述块一次后,该循环只向站点添加1,直到为5。请准确解释您预期会发生什么以及会发生什么。