Help

The world population reached 6 billion people in 1999 and was growing at the rate of 1.4 percent each year. Assuming that the population will continue to grow @ the same rate, write a program to determine when the population will exceed 10 billion.

Private Sub cmdbutton_Click()
Dim population As Single
picWhen.Cls
pop = 6000000
yr = 1999
Do pop > 10000000
picWhen.Print "In"; yr; "Population will be"; pop;
pop = pop * 0.00014
Loop
End Sub


Please tell me the write way to write this

Comments

  • : The world population reached 6 billion people in 1999 and was growing at the rate of 1.4 percent each year. Assuming that the population will continue to grow @ the same rate, write a program to determine when the population will exceed 10 billion.
    :
    : Private Sub cmdbutton_Click()
    : Dim population As Single
    : picWhen.Cls
    : pop = 6000000
    : yr = 1999
    : Do pop > 10000000
    : picWhen.Print "In"; yr; "Population will be"; pop;
    : pop = pop * 0.00014
    : Loop
    : End Sub
    :
    :
    : Please tell me the write way to write this
    :

    I wont give you the actual code, but I will give you some hints on how to solve the problem ...

    1. Since the start population and target destination is divisible by ten, you can scale down the numbers by chopping off an equal amount of zeros from each number. For instance, use the number 6 and 10 instead of 6 billion and 10 billion. Other numbers that will work are ...

    60 and 100
    600 and 1000
    6000 and 10000

    No matter which number combination above, you will get the same result in the long run.

    2. %1.4 is really 0.014. If you remember your basic math, your really dividing 1.4 by 100 or moving the decimal two places to the left.

    3. Then basically you need to build some kind of loop which adds %1.4 percent to the current population for each iteration, until the population is greater-than equal to the target population. With each iteration of the loop, you are basically going to add one to the year.

    4. You need to work with visual basic data types that can store numbers with decimals.



  • Private Sub cmdbutton_Click()
    Dim pop As Single
    picWhen.Cls
    pop = 6
    Year = 0
    Do While pop >= 10
    picWhen.Print "In"; Year; "Population will be"; pop;
    pop = pop * 0.00014
    Year = Year + 1
    Loop
    End Sub
    I changed everything. I'm getting an error Argument not optional.

    : : The world population reached 6 billion people in 1999 and was growing at the rate of 1.4 percent each year. Assuming that the population will continue to grow @ the same rate, write a program to determine when the population will exceed 10 billion.
    : :
    : : Private Sub cmdbutton_Click()
    : : Dim population As Single
    : : picWhen.Cls
    : : pop = 6000000
    : : yr = 1999
    : : Do pop > 10000000
    : : picWhen.Print "In"; yr; "Population will be"; pop;
    : : pop = pop * 0.00014
    : : Loop
    : : End Sub
    : :
    : :
    : : Please tell me the write way to write this
    : :
    :
    : I wont give you the actual code, but I will give you some hints on how to solve the problem ...
    :
    : 1. Since the start population and target destination is divisible by ten, you can scale down the numbers by chopping off an equal amount of zeros from each number. For instance, use the number 6 and 10 instead of 6 billion and 10 billion. Other numbers that will work are ...
    :
    : 60 and 100
    : 600 and 1000
    : 6000 and 10000
    :
    : No matter which number combination above, you will get the same result in the long run.
    :
    : 2. %1.4 is really 0.014. If you remember your basic math, your really dividing 1.4 by 100 or moving the decimal two places to the left.
    :
    : 3. Then basically you need to build some kind of loop which adds %1.4 percent to the current population for each iteration, until the population is greater-than equal to the target population. With each iteration of the loop, you are basically going to add one to the year.
    :
    : 4. You need to work with visual basic data types that can store numbers with decimals.
    :
    :
    :
    :

  • First off, the error is caused by the fact that you forgot to "Dim" the "Year" variable.

    Other problems you will have:

    1. You have an infinite loop (you do not have a proper stop condition)
    2. You should be calling the Print function after the loop
    3. Your decimal for the percent is wrong (look in my last response)
    4. The year variable should be initialized to the year 1999
    5. In the loop, you are not properly adding a percentage of the population ... this line is wrong ...

    [code]
    pop = pop * 0.00014
    [/code]

    Not only is the decimal wrong, you are essentially storing the value of the "pop" variable multiplied by the decimal and overwritting "pop".

    This basically means that, after the first loop "pop" will equal

    0.084 because of (6 * 0.014) when it ...
    should equal 6.084 (6 + (6 * 0.014))

    You need to rewrite this expression to add the value of "pop" times the decimal to the current value of "pop".


    : Private Sub cmdbutton_Click()
    : Dim pop As Single
    : picWhen.Cls
    : pop = 6
    : Year = 0
    : Do While pop >= 10
    : picWhen.Print "In"; Year; "Population will be"; pop;
    : pop = pop * 0.00014
    : Year = Year + 1
    : Loop
    : End Sub
    : I changed everything. I'm getting an error Argument not optional.
    :
    : : : The world population reached 6 billion people in 1999 and was growing at the rate of 1.4 percent each year. Assuming that the population will continue to grow @ the same rate, write a program to determine when the population will exceed 10 billion.
    : : :
    : : : Private Sub cmdbutton_Click()
    : : : Dim population As Single
    : : : picWhen.Cls
    : : : pop = 6000000
    : : : yr = 1999
    : : : Do pop > 10000000
    : : : picWhen.Print "In"; yr; "Population will be"; pop;
    : : : pop = pop * 0.00014
    : : : Loop
    : : : End Sub
    : : :
    : : :
    : : : Please tell me the write way to write this
    : : :
    : :
    : : I wont give you the actual code, but I will give you some hints on how to solve the problem ...
    : :
    : : 1. Since the start population and target destination is divisible by ten, you can scale down the numbers by chopping off an equal amount of zeros from each number. For instance, use the number 6 and 10 instead of 6 billion and 10 billion. Other numbers that will work are ...
    : :
    : : 60 and 100
    : : 600 and 1000
    : : 6000 and 10000
    : :
    : : No matter which number combination above, you will get the same result in the long run.
    : :
    : : 2. %1.4 is really 0.014. If you remember your basic math, your really dividing 1.4 by 100 or moving the decimal two places to the left.
    : :
    : : 3. Then basically you need to build some kind of loop which adds %1.4 percent to the current population for each iteration, until the population is greater-than equal to the target population. With each iteration of the loop, you are basically going to add one to the year.
    : :
    : : 4. You need to work with visual basic data types that can store numbers with decimals.
    : :
    : :
    : :
    : :
    :
    :

  • : First off, the error is caused by the fact that you forgot to "Dim" the "Year" variable.
    :
    : Other problems you will have:
    :
    : 1. You have an infinite loop (you do not have a proper stop condition)
    : 2. You should be calling the Print function after the loop
    : 3. Your decimal for the percent is wrong (look in my last response)
    : 4. The year variable should be initialized to the year 1999
    : 5. In the loop, you are not properly adding a percentage of the population ... this line is wrong ...
    :
    : [code]
    : pop = pop * 0.00014
    : [/code]
    :
    : Not only is the decimal wrong, you are essentially storing the value of the "pop" variable multiplied by the decimal and overwritting "pop".
    :
    : This basically means that, after the first loop "pop" will equal
    :
    : 0.084 because of (6 * 0.014) when it ...
    : should equal 6.084 (6 + (6 * 0.014))
    :
    : You need to rewrite this expression to add the value of "pop" times the decimal to the current value of "pop".
    :

    Which is quite basic math actually: The population grows 1.4% per year. So added is the 1.4% * population. Which would equal: Pop + Pop * 0.014
    This can be rewritten if you like: Pop * 1.014
    The 1.014 means a total population of 101.4% relative to the last year.
    Good luck

    Greets...
    Richard

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories