Hello all,

I'm working with exponentiation and I have an assignment to write a code for loop initialization and loop body but unfortunately, I don't even know what that means.

I was given the following information:

Input x // can be any float
Input y // has to be a positive integer

Set result = 1 // initial value

For i = 1 to y
result = result * x

Can anyone PLEASE translate what that means and show me an example of a loop initialization and loop body code? Please advise if you need more info. I apologize in advance for being slow.

Recommended Answers

All 2 Replies

Input = cin
x is a float
y is a int
r is a int

for i to y means :

for(int i = 1; i < y; i++)
{
   //code goes here
}

The "code goes here" part is result = result * i;

Input = cin
x is a float
y is a int
r is a int

for i to y means :

for(int i = 1; i < y; i++)
{
   //code goes here
}

The "code goes here" part is result = result * i;

Thanks for the help. I'll try that. I'm still very new to programming.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.