关于VB编程的一道作业
- 提问者网友:心牵心
- 2021-07-16 07:26
- 五星知识达人网友:患得患失的劫
- 2021-07-16 08:17
Private Sub Command1_Click() '计算按钮
Dim num As Integer, a As Integer, day As Integer
a = 1
day = Int(Text1.Text)
If day <= 0 Or day >7 Then
MsgBox "你输入的天数不正确,请重新输入", vbCritical + vbOKOnly, "错误"
Exit Sub
End If
If day = 7 Then
Print "当天的桃子数是:1"
Exit Sub
End If
While day <= 6
num = (a + 1) * 2
a = num
day = day + 1
Wend
Print "当天的挑子数是:" & num
End Sub
- 1楼网友:北方的南先生
- 2021-07-16 08:25
Private Sub Command1_Click() Dim a, b, s As Integer a = 1 '第7天吃完后就是这一个了,令a=1 For i = 7 To 1 Step -1 '吃之前的桃子数 ,从第7天吃之前开始算起 a = (a + 1) * 2 '每天吃之前剩的桃子数 Next Print vbCrLf & vbCrLf & vbCrLf & "结果猴子吃了:" & a & "个." '打印结果 End Sub
Private Sub Form_Load() Form1.Show Form1.Print "题:" & vbCrLf & _ "小猴在一天摘了若干个桃子," & vbCrLf & _ "当天吃点一半多一个;第二天接着吃了剩下的桃子的一半多一个;" & vbCrLf & _ "以后每天都吃尚存桃子的一半零一个,到第7天早上要吃的时候只剩下一个了," & vbCrLf & _ "问小猴那天一共摘了多少个桃子?" End Sub
运行结果: