Results 1 to 2 of 2

Thread: Using Loops - Please help

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    4

    Unhappy Using Loops - Please help

    I'm killing myself over here. I'd appreciate any help offered.

    I'm trying to write a program that will sum values in this series (ð/4=1-1/3+1/5-1/7+1/9-...) and print the estimate for ð. I would like for the user to choose whether to sum 100, 200, 300, 400, or 500 values to estimate ð. The more values that are added, the closer the sum *4 will be to 3.1416.

    Thank you for your help.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Will this do ?

    Code:
    Option Explicit
    Dim sigma As Double
    Dim doAdd As Boolean
    
    Private Sub Command1_Click()
        doAdd = True
        sigma = 0
        If (Text1.Text <> "") Then
            If (IsNumeric(Text1.Text)) Then
                Dim i As Long
                For i = 3 To Text1.Text Step 2
                    If (doAdd) Then
                        sigma = sigma + (1 / i)
                    Else
                        sigma = sigma - (1 / i)
                    End If
                    doAdd = Not doAdd
                Next i
                sigma = 1 - sigma
                sigma = 4 * sigma
                MsgBox "Answer : " & sigma
            End If
        End If
    End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width