我試圖編寫的程序假設將由巴士公司使用。該公司有18輛巴士,每輛巴士的用戶必須能夠通過輸入框輸入巴士上有多少人。不斷重置循環內的最小值和最大值vb.net
如果有超過55人乘坐公共汽車,那麼公共汽車會被分類爲滿。當收集所有18輛公交車的數據時,必須輸出每輛公共汽車的平均乘客數量以及最小和最大數量。
這裏是我到目前爲止編碼:
Public Class FirstBus
Dim passengers As Integer
Dim TotalPassengers As Integer
Dim bus As Integer
Dim FullBus As Integer
Dim min As Integer
Dim max As Integer
Dim average As Decimal
Private Sub FirstBus_Load(sender As Object, e As EventArgs) Handles MyBase.Load
average = TotalPassengers/18
lblOutput.Text = "Average number of passengers = " & average & vbNewLine & "Maxium number of passengers = " & max & vbNewLine & "Minimum number of passengers = " & min
bus = 1
min = 1000
max = 1
End Sub
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
For i = 1 To 18
passengers = InputBox("Enter the number of passengers on bus number " & bus)
If passengers > 54 Then
FullBus = FullBus + 1
End If
If passengers > max Then
max = passengers
ElseIf passengers < min Then
min = passengers
End If
TotalPassengers = TotalPassengers + passengers
bus = bus + 1
Next i
End Sub
的問題是,當我輸入的所有18條總線的數據,平均值,最小值和最大值都輸出爲0,我需要找到一種方式輸出這些作爲實際的平均值,最小值和最大值
我不知道,如果這兩個方法都以相同的形式,但只是看着它,負載之前執行這些值按鈕按下。所以你也應該按下按鈕後顯示信息。 –
一切都在一種形式,我已經把負載移動到正確的位置,現在的代碼是好的,我踢我自己不接受這個 –