Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single, l As Single a = InputBox("a=?") b = InputBox("b=?") c = InputBox("c=?") l= a + b + c If a >= l Or b >= lOr c >= lThen Print "不能构成三角形" Else Print "三角形周长为:" a + b + c End If End Sub谁能帮帮看看这个VB程序对不对。
- 提问者网友:别再叽里呱啦
- 2021-05-09 16:24
- 五星知识达人网友:独行浪子会拥风
- 2021-05-09 17:35
判断能否构成三角形的地方错了
修改如下:
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single, l As Single
a = InputBox("a=?")
b = InputBox("b=?")
c = InputBox("c=?")
If a + b > c Or b + c > a Or a + c > b Then
Print "不能构成三角形"
Else
Print "三角形周长为:"; a + b + c
End If
End Sub
- 1楼网友:爱难随人意
- 2021-05-09 19:18
只是求三角形周长. 那么只要输入的边长能够构成三角形.就将三条边相加输出就对了.
三角形边长的判断条件是任意两边之和大于第三边!
所以更改判断条件. 修改如下:
Private Sub Command1_Click() Dim a As Single, b As Single, c As Single, l As Single a = InputBox("a=?") b = InputBox("b=?") c = InputBox("c=?") If a + b <= c Or b + c <= a Or a + c <= b Then
'一旦任意两边之和小于或等于第三边.则不能构成三角形 Print "不能构成三角形" Else Print "三角形周长为:"; a + b + c End If End Sub
- 2楼网友:旧脸谱
- 2021-05-09 19:04
Option Explicit
Dim a As Single, b As Single, c As Single, p As Single, S As Single Private Sub Command1_Click() On Error GoTo e a = InputBox("a=") b = InputBox("b=") c = InputBox("c=") p = (a + b + c) / 2 If a < p And b < p And c < p Then S = Sqr(p * (p - a) * (p - b) * (p - c)) MsgBox S Else GoTo e End If Exit Sub e: MsgBox "不能构成三角形" End Sub