3 Replies - 13387 Views - Last Post: 18 December 2006 - 08:26 PM Rate Topic: -----

#1 uppedcool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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);
	

		{
				cout<<"please enter a integer\n\n\t\t";
				cin>> base;
				cout<<"please enter a power\n\n\t\t";
				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  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 uppedcool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#4 jstephens  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1