dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2017
    Posts
    2

    hypotenuse of a right triangle

    Develop a C# console application that computes the hypotenuse of a right triangle. The computation of the hypotenuse

    of a right triangle is based on the Pythagorean Theorem: c2 = a2 + b2 and the hypotenuse, c ("long side") of the triangle

    can be computed with the formula the hypotenuse is equal to the square root of the side a squared plus side b squared.

    The application should take as many side pairs inputs as the user desires and calculate each until the user enters a zero

    for both side one and side two (sentinel loop). You should use at least two (2) Math class methods.

    The output should look something like this:

    enter length of first side: 3

    enter length of second side: 4

    The hypotenuse is 5

    enter length of first side: 3.44

    enter length of second side: 4.88

    The hypotenuse is 5.97059461025449

    enter length of first side: 10.55

    enter length of second side: 33.0

    The hypotenuse is 34.6453820876607

    enter length of first side: 0

    enter length of second side: 0

    Press any key to continue . . .

    I get that the hypotenuse is 5, but I'm not converting the inputs correctly. My problem is trying to find away to convert a string number input to a numeric value type.

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,144

    Re: hypotenuse of a right triangle

    1. Do you develop a C++ or C# application?
    2. What is your exact problem with the code?
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,210

    Re: hypotenuse of a right triangle

    [moved from c++ to c# forum as question relates to c#]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.1)

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)