Answer not doubling for correct response

Posted on 2009-02-21
Last Modified: 2013-11-13
Within my formula code, I cannot get my response to properly display the output of the Pythagorean theorem formula: a2 + b2 = c2. How do I properly code to get correct response?
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click

        If Theorem.Checked Then


            txtOutput.Text = Math.Pow(NUDradius.Value, 2) + Math.Pow(NUDheight.Value, 2)

        ElseIf Cylinder.Checked Then

            'cylinder volume

            txtOutput.Text = Math.Pow(NUDradius.Value, 2) * NUDheight.Value * Math.PI

        End If

    End Sub

Open in new window

Question by:probeg
    LVL 39

    Accepted Solution

    What do you mean with incorrect? The result of your formula is the quadrature of the hypotenuse, which, to show up as the length of the hypotenuse, first has to be square rooted:

    Math.Sqrt(Math.Pow(NUDradius.Value, 2) + Math.Pow(NUDheight.Value, 2))

    Btw: I don't know what NUDradius is, but it sounds like something of the radius of a circle, are you sure that's the value you need? Shouldn't it be something like height / width of the rectangle/triangle?
    LVL 9

    Expert Comment

    by:Ken Fayal
    If you are trying to obtain the value of c then you need to use the following:

    txtOutput.Text = Math.Sqrt(Math.Pow(NUDradius.Value, 2) + Math.Pow(NUDheight.Value, 2))

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now