Thread: What is wrong with this funtion!?

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    9

    What is wrong with this funtion!?

    Code:
    //#includes and blablabla...
    
    double radius_circ (double a, double b, double c)
    {
        double semi_per;
        semi_per = (a + b + c) / 2;
        double result;
        result = (a * b * c) / (4 * (sqrt (semi_per * ((semi_per - a) * (semi_per - b) * (semi_per - c )))));
        return result;
    }
    
    void run_this (void)
    {
      double a;
      double b;
      double c;
      while (scanf ("%lf%lf%lf", &a, &b, &c) != EOF)
      {
        double z = radius_circ (a, b, c);
        printf ("%0.6f\n", z);
      }
    }
    
    //main run_this...
    Objective:
    Program a function that computes the radius of the circle circumscribed in a triangle, given the lengths of the sides. Use the formula r = abc / 4 (sqrt (s (s-a) (s-b) (s-c)), where a, b and c represent the sides and s represents the semi-perimeter.
    http://www.efunda.com/math/areas/ima...CircleGen1.gif
    http://www.efunda.com/math/areas/ima...CircleGen2.gif

    Last edited by Grilofuzeta; 10-11-2013 at 07:37 AM. Reason: add *

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you do not have * (multiplication) in every place you want to multiply 2 value.

    Compiler cannot read your mind - you need to write everything you want it to do.

    Also what will happen if scanf returns 0, 1 or 2?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Sep 2013
    Posts
    9
    tested 0, 1 , 2
    Code:
    0 1 2
    -1.#IND00
    ^Z
    
    Process returned 0 (0x0)   execution time : 40.839 s
    Press any key to continue.
    I "only" (not sure) need to add something to make this program to use only positive numbers. Thx

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You missed vart's point. scanf() does not only return EOF to report problems.

    What do you expect to happen if a negative value is passed to sqrt()? How many real triangles with have a size with zero length?
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help on using a funtion
    By Ambuter in forum C Programming
    Replies: 5
    Last Post: 10-27-2011, 03:10 PM
  2. What's wrong with my funtion :(
    By bikr692002 in forum C++ Programming
    Replies: 8
    Last Post: 04-14-2006, 05:52 PM
  3. how to add my own funtion into a library
    By nitro in forum Tech Board
    Replies: 1
    Last Post: 09-11-2005, 02:30 AM
  4. is this funtion ok?
    By kermit in forum C Programming
    Replies: 8
    Last Post: 08-22-2003, 05:28 PM
  5. HELP!!! parameters of funtion???????
    By WildLyxn in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2002, 11:19 PM

Tags for this Thread