return as a double?

This is a discussion on return as a double? within the C++ Programming forums, part of the General Programming Boards category; is there a way to make return count as a double instead of an int? thanks...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    33

    return as a double?

    is there a way to make return count as a double instead of an int? thanks

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    If you mean just any function then sure, declare it as
    double func ( args );
    If you are talking about main then you really don't want to return anything but an int.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    33
    well, here's my program:

    #include <iostream.h>
    #include <math.h>

    int pyth(double one, double two);


    int main()
    {
    double product, one, two;
    product = pyth(one, two);
    cout<<"Please enter two sides of a right triangle\n";
    cin >>one>>two;
    cout<<"the hypotenuse of the right triangle is "<<pyth(one, two)<< " long"<<endl;
    return 0;
    }
    int pyth(double one, double two)//takes two number, squares them, adds them, then squares the product.
    {
    one = pow(one, 2);
    two = pow(two, 2);
    one = one + two;
    two = sqrt(one);
    return two; //can I have this return two as a double instead of an int?
    }

    as you can see, I need these numbers to be more precise then just an int. or if there's an easyer way to do this, thanks

  4. #4
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    just change the function type to double, not int...
    My Website

    "Circular logic is good because it is."

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    33

    oh...

    ohh... well now I feel stupid, i tryed this and it gave me an error the first time, now it works.... thanks

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    5

    Thumbs up

    yea, that's it... pretty straightforward

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 09:36 PM
  3. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 04:33 PM
  4. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  5. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21