Connecting Tech Pros Worldwide Forums | Help | Site Map

Creating my own functions.

Newbie
 
Join Date: Oct 2007
Posts: 25
#1: Oct 31 '07
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's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Oct 31 '07

re: Creating my own functions.


Quote:

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:
Expand|Select|Wrap|Line Numbers
  1. temp double;
  2. temp = x;
  3. <your for loop>
  4. temp= temp * x;
  5. <end of loop>
  6. return temp;
  7.  
Reply