# Writing a pow function

Page 1 of 1

## 3 Replies - 13387 Views - Last Post: 18 December 2006 - 08:26 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=22064&amp;s=936e291b8eb7f20e05a7c5cfc9b55e64&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 uppedcool

Reputation: 0
• Posts: 2
• Joined: 14-December 06

# Writing a pow function

Posted 14 December 2006 - 09:47 AM

```void powers()

{
int base;
int exponent;
double end;

while(base>-1);

{
cin>> base;
cin>> exponent;

for(base=base; base<=-1; base++)
{
cout<<base*base;

}

}

_getch();
}

```

this is the assignment

• Write a function that will raise an integer value to the nth power. The user must enter the integer, and the power. The function must display the output in the following format:

xx raised to the power x = xx

For example, if the integer is 7, and the power is 2, the output would be:

7 raised to the power 2 = 49

The function should loop repeatedly until the user enters a negative number for the integer (the negative number is called a sentinel in computerese).

can someone plz help me or at least tell me what im doing wrong?

This post has been edited by Dark_Nexus: 16 December 2006 - 01:04 AM

Is This A Good Question/Topic? 0

## Replies To: Writing a pow function

### #2 jstephens

Reputation: 2
• Posts: 214
• Joined: 07-November 05

## Re: Writing a pow function

Posted 14 December 2006 - 09:59 AM

I would rewrite you for loop to something like the following.
```for (int e = 0; e < exponent; e++)
{
base *= base;
cout << "Base is " << base;
}

```

also you last code is missing the / slash.

### #3 uppedcool

Reputation: 0
• Posts: 2
• Joined: 14-December 06

## Re: Writing a pow function

Posted 18 December 2006 - 10:26 AM

thx alot i think i understand it now

### #4 jstephens

Reputation: 2
• Posts: 214
• Joined: 07-November 05

## Re: Writing a pow function

Posted 18 December 2006 - 08:26 PM

did you get it solved. After reading you thread I decided to try and build my own pow() also. It worked pretty good. don't have the code on me it is at work.