我无法弄清楚为什么我的计算不起作用。我正在做 1 到 12,它给了我 12 个输入,但我的输入计为 13?我错过了什么。
如果我将其更改为 0 到 11 相同的东西。我不确定问题是什么,但我看不到它,也不知道在哪里看。
我需要以 12 个周期结束,intEntries 为 12...帮助!谢谢!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'initialize accumulator
Dim decEntries As Decimal
' For loop to ask for input.
For decEntries = 1 To 12 Or strMonthlyAvg = " "
strMonthlyAvg = InputBox("Please Enter the Average for Month # " & decEntries & ":")
lstTemps.Items.Add(strMonthlyAvg)
decMontlyAvg = Convert.ToDecimal(strMonthlyAvg)
' This will add the montly average to the total Average Temperature for
' calculations
decTotalTemp += decMontlyAvg
Next
' Calculation to provide the average temp for all entered values
decAnnualAvg = decTotalTemp / decEntries
' convert annual average to string
strAnnualAvg = Convert.ToString(decAnnualAvg)
' Display the results for the user
lblResults.Text = "The average annual temperature " & vbCrLf &
"based on your entries is: " & strAnnualAvg & "."
End Sub