Dim n As Integer = 1, year As Integer
Do Until 6000000000 / (2 * n) = 6000000
year = 2008 - 40 * n
n = n + 1
Loop
txtResult.Text = "The world population would have been less than 6 million in the year " & year
正如我上面展示的代码,我试图制定我的计划,以确定2008年60亿人口减少到或少于600万的人口(假设人口每40年增加一倍)。但是,当我运行程序时,它不会显示1608年的结果。 任何人都可以帮助我纠正我的代码是非常有帮助的!非常感谢。
答案 0 :(得分:2)
在VBA中,您将拥有以下代码按预期工作:
Sub qtest()
Dim n As Integer, year As Integer
Dim Population As Double
n = 1
year = 2008
Population = 6000000000#
Do Until Population <= 6000000
Population = Population / 2
year = year - 40
n = n + 1 'you don't need it but I left it here
Loop
MsgBox "The world population would have been less than 6 million in the year " & year
End Sub