我的计算有效,但每次运行程序时,我的输出都是“负数,不超过”结果。我对这一切都很陌生,所以请提供任何建议。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim foodname As String = MaskedTextBox1.Text
Dim calories As Integer = MaskedTextBox2.Text
Dim fat As Integer = MaskedTextBox3.Text
Dim calculation As Double = (fat * 9) / calories
Dim positive As String = "which exceeds AHA recommendation"
Dim negative As String = "which does not exceed AHA recommendation"
ListBox1.Items.Clear()
If ((fat * 9) / calories) > (0.3 * 100) Then
ListBox1.Items.Add(foodname & " contains " & FormatPercent(calculation) & " calories from fat, " & positive)
ElseIf ((fat * 9) / calories) < (0.29 * 100) Then
ListBox1.Items.Add(foodname & " contains " & FormatPercent(calculation) & " calories from fat, " & negative)
End If
End Sub
End Class
答案 0 :(得分:1)
这有帮助吗?
If ((fat * 9) / calories) > (0.3 * 100) Then
ListBox1.Items.Add(foodname & " contains " & FormatPercent(calculation) & " calories from fat, " & positive)
Else
ListBox1.Items.Add(foodname & " contains " & FormatPercent(calculation) & " calories from fat, " & negative)
End If
这里只有两个选项,不需要两个条件。要么第一个是真的,要么必须是第二个