
-----------------------------------
steven.yuan3
Wed Jan 27, 2010 6:06 pm

i need help with the logic
-----------------------------------
this is the question i am working on, im not sure how to put it into a for or while loop. any ideas?

-----------------------------------
jbking
Wed Jan 27, 2010 6:17 pm

Re: i need help with the logic
-----------------------------------
Let's go over a few different points here.  Consider a for loop for a moment.  What do you want to be set at the start of the loop?  What exit criteria should there be?  What kind of increment should happen in the loop?

For example, to go from 1 to 10 in steps of 2, here is the C++:

[code]
for (int i = 1; i < 10 ; i=i+2)
{
  // do something here with the i.
}[/code]

If you still need help, please specify where your difficulty is as I don't think the question is that hard, myself.

-----------------------------------
wtd
Wed Jan 27, 2010 11:12 pm

RE:i need help with the logic
-----------------------------------
What's the same every time?

4

What changes?

The denominator and the use of addition or subtraction.

How does the denominator change?

It always increments by 2.

How does the arithmetic operator change?  

It adds every other time around.

-----------------------------------
HRI
Wed May 05, 2010 7:46 pm

Re: i need help with the logic
-----------------------------------
For the adding and subtracting part, -1 can be a very useful number if used in the right way.
