Successively divide a Positive Integer in VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stephie3883
    New Member
    • Feb 2013
    • 6

    Successively divide a Positive Integer in VBA

    Hi,
    I need to create a code in VBA to successively divide a positive integer N (N=88) by another positive integer D (D=13). I need to determine how many divisions it would take to reduce the resulting number to >= .000001 using a conditional loop.
    so far i have:

    Code:
    Sub Ediv()
    Dim N As Integer
    Dim D As Integer
    Dim Z As Integer
    Dim intCount as Integer
    
    N=88
    D=13
    intCount=0
    
    Do While Z>=.000001
          Z=N/D
          intCount=intCount+1
    loop
    
    End Sub
    I know i am getting stuck on the algorithm because i do not know how to continuously divide by D until Z=.000001.
    Please help i have been stuck on this problem for HOURS!!
    Last edited by Rabbit; Feb 28 '13, 04:52 AM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    You need to set z to n outside the loop and inside the loop, z needs to be set to z / d so that it saves the result.

    Comment

    Working...