The country A has 50M inhabotants, and its population grows 3% per year. The country B, 70M and grows 2% per year.Tell in how many years A will surpass B.correct the answer

• Question

• Dim years As Integer
Dim rate As Decimal
Dim popn As Integer
Dim country, a, b As String
Console.WriteLine("a=50M")
Console.WriteLine("b=70M")
Console.WriteLine("a rate=0.03")
Console.WriteLine("b rate=0.02")
a = 50M
b = 70M
years = 0
Do While a < b
a = a + 0.03 * a
b = b + 0.02 * b
years = years + 1
Loop
Console.WriteLine("a will surpass b in" & years)
Saturday, August 10, 2019 7:44 AM

All replies

• Hi,

I guess it's a school assignment and I hesitate to show code...
You need to use Integer, Single, etc for computing of population.
```Dim Rate_A As Single = 1.03
Dim Rate_B As Single = 1.02
Dim Pop_A As Single = 50.0
Dim Pop_B As Single = 70.0
Dim Years As Integer = 0
' ---
Do Until Pop_A > Pop_B
Years += 1
Pop_A = Pop_A * Rate_A
Pop_B = Pop_B * Rate_B
Loop
' ---
Console.WriteLine("A will surpass B In " & Years & " years")
Console.WriteLine("A = " & Pop_A.ToString("0.00"))
Console.WriteLine("B = " & Pop_B.ToString("0.00"))