trying to understand a lesson

i'm trying to teach my self C++ and was doing ok until i hit a typo in the book. it's an older deitel book. it asks to write a bunch of statements and then use them in a program. the typo involves this question:

g) test y to see if it is less than or equal to x.

the answer given is:

g) if(i <= y)

i can live with that being wrong. the problem comes with the next question and my lack of ability to remember math most likely.

"write a C++ program that uses the previous statements to calculate x raised to the y power. the program should use a while repetition control structure."

the base and exponent are input by the user, why would it even need to use while in the first place? maybe it's just the typo that's confusing me? or my forgetting simple math? either way, if ya'll could point me in the right direction to figure this out it would be greatly appreciated.
How would you calculate the xy, being y a natural number? Don't write any code, just describe the procedure in English.
Last edited on
x * x if y = 2, x * x * x if y = 3, etc..

at least i think that's how it's supposed to work.

in the problem, x and y are user input. i and power are initialized at 1. i guess my confusion is why i and power are even needed?
In other words, you would multiply x by itself N times. How would you have a computer do it?

Another way to look at it is:

x^2 = x * x
x^3 = x * x^2 (ie, previous answer)
x^4 = x * x^3 (ie, previous answer)

thanks guys. i'm still not exactly sure how to write it out, but at least i understand what everything does now.
Topic archived. No new replies allowed.