Creating my own functions.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • midknight5
    New Member
    • Oct 2007
    • 25

    Creating my own functions.

    Hey guys, as I progress through my C++ education ive started getting into headers and drivers, so I figured for good practice I would make my own header file that contains function prototypes and a implementation file for testing.

    I want to make my own version of pow, so ive made a functions called:
    double power(double x, double y);

    Now we all know how a power works, its multiplies number x by itself y number of times but im unsure of how to implement this. I figured a for loop would work.

    for (int i = 0; i < y; i++)
    {
    // something to do with x*x?
    }

    But from here I get stuck, any ideas?
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by midknight5
    Hey guys, as I progress through my C++ education ive started getting into headers and drivers, so I figured for good practice I would make my own header file that contains function prototypes and a implementation file for testing.

    I want to make my own version of pow, so ive made a functions called:
    double power(double x, double y);

    Now we all know how a power works, its multiplies number x by itself y number of times but im unsure of how to implement this. I figured a for loop would work.

    for (int i = 0; i < y; i++)
    {
    // something to do with x*x?
    }

    But from here I get stuck, any ideas?
    Have a temporary variavle something like this:
    [code=c]
    temp double;
    temp = x;
    <your for loop>
    temp= temp * x;
    <end of loop>
    return temp;
    [/code]

    Comment

    Working...