Reputation: 21
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
As the code that I showed above, I tried to make my program to determine in which year the population from 6 billion in 2008 reduced to or less than 6 million.(Assume the population is doubled every 40 years). However, when I run the program, it won't show result which is the year 1608. It would be so helpful is anyone could help me to correct my code! Thanks a lot.
Upvotes: 0
Views: 80
Reputation: 19067
In VBA you will have the following code working as expected:
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
Upvotes: 2