大家好,我不明白 for each 循环在这种特殊情况下是如何工作的。我有一个 500 加仑的水箱将在 24 小时后用于炸鱼。该水箱每小时泄漏率为10%的剩余水。如果水箱下降到 100 加仑以下,鱼就会全部死亡(立即)。这就是问题所在,每小时添加额外的加仑水以保持最终价值高于 100 加仑。然后在列表框中显示每小时后剩余的加仑数。
这是程序的图片,可以查看我正在使用哪些控件:
我需要帮助来降低逻辑。
500 * .10 = 50
500 - 50 = 450
依此类推……但是我需要将所有数学计算打印到 listBox 中,如下所示:
任何帮助表示赞赏,我正在学习,所以不要太苛刻。这是我的代码:
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim Gallons As Double = 500
Dim LeakRate As Double = 0.1
Dim Remainder As Integer
Dim Time As Integer = tkbSlider.Value
lstRemainingGallons.Items.Clear()
For n As Integer = 1 To 24
Remainder = CInt(Gallons * LeakRate) - Time
Gallons = CInt(Gallons - Remainder)
If Gallons <= 99 Then
MessageBox.Show("Fish died at " & n & " hours when the remaining gallons were " & Gallons, "Dead and Stinking Fish", MessageBoxButtons.OK
)
Exit Sub
End If
**If Gallons <= 100 Then
MessageBox.Show("Hello You Have Passed", "Fish Frying Time!")
End If**
lstRemainingGallons.Items.Add("Hour # " & n & " - " & Gallons & "gallons")
Next
End Sub
End Class