嗨,我想在vb.net中创建一个程序,找到一个数字的平均值只使用一个变量的值与inputbox和第二个计数应该是负数,但我不能得到准确的answere 这里是代码如何在vb.net中找到平均值
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim num, count As Integer
num = InputBox("Please enter number") 'for first entry
While num > 0 ' here we have to check it that the num is not negative then to start
num = InputBox("Please enter number")
num += num
count += 1 'this will calculate how many times number added
End While
MsgBox("Average is " & num/count)
End Sub
你能使用前退出循环一个'list(of integer)'而不是'in teger',以保存用户给出的值。然后,您可以在列表中保存用户给出的值的总和。只给你2个变量。我可以将一些示例代码放在一起,但我不熟悉'inputbox'表单工具,并确定为什么需要num> 0。 – Pezzzz