It is currently Mon May 20, 2013 7:08 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: C++ Help.
PostPosted: Tue Feb 23, 2010 7:09 pm 
Offline
User avatar
.: Level III :.

Joined: Sat Nov 17, 2007 12:52 am
Posts: 407
Location: London
iTrader:
Gender: Male
Reputation point: 12
H3nry will become famous soon enough


Winner Award

Hey.

Ok, I have a program in which the user enters a value and then I call a function which uses that value for a calculation.

Code:
int xpower(int x)
{
   int n = 3;
   int power = 1;
   int i = 0;

   while (i < n)
   {
      power = power * x;
      i = i + 1;
   }
   return power;
}


So the value the user enters is x and n is the power....so x^n.
The equation I must use...n HAS to start at 3. I want to use the function, return the value then increment n by 2, the problem I think I have is that everytime I use the function i basically reset n to 3....so is there any way I can get around this?

_________________
Image


Top
 Profile  
 
 Post subject: Re: C++ Help.
PostPosted: Tue Feb 23, 2010 7:17 pm 
Offline
User avatar
.: Level III :.

Joined: Sat Nov 17, 2007 12:52 am
Posts: 407
Location: London
iTrader:
Gender: Male
Reputation point: 12
H3nry will become famous soon enough


Winner Award

DUUUUUUUUUUUUUUUUUUUUUUHHHHHHHH, man I miss the sillyest things :x.

I've just seen it myself loool.

I took n out of the function, it didn't need to be there at all.
I initialised n in the main body and added another parameter in the function.

Thanks for looking anyway o_O

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
* FAQ

Powered by phpBB © 2000- phpBB Group
NEOPETS, characters, logos, names and all related indicia are trademarks of Neopets, Inc., © 1999-. © denotes Reg. US Pat. & TM Office. All rights reserved.
Website © neofriends.net - this site is in no way affiliated with Neopets, Inc or Viacom International, Inc.

phpBB SEO