problem with while loops

This is a discussion on problem with while loops within the C++ Programming forums, part of the General Programming Boards category; This is your problem:
Code:
counter = (2 * firstNum) - 1;
I still don't see a purpose for it ...

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Use your own code MyntiFresh. You changed too much between your last two versions. Get one thing to work first before moving on to the next. If you add the counter to the code above that uses the % to find even or odd, and then remove all the (2 * firstNum) - 1 stuff which is totally unnecessary, then you will be closer to your solution for even/odd. Once that is done you can worry about the sum and other stuff.

The first part to fixing the sum loop is to reset counter to the value of firstNum before that loop. Once you do that, the sum part works as well, you just have to figure out where your output statements should be to make it look nicer.

The first part to fixing the sum loop is to reset counter to the value of firstNum before that loop. Once you do that, the sum part works as well, you just have to figure out where your output statements should be to make it look nicer.

Alright, I reset counter back to firstNum. But I'm still getting the same infinite loop when I execute. Could it be somewhere else in my program that's making it do that? I know they frown upon people putting up their entire code, but I'm just getting so frustrated with this.

I highly suggest commenting out everything after the sum (up to the return 0) and making sure that part works. It's better to get each part to work one at a time. If I do that, then now the odd part and the sum part work pretty well. Concentrate on those to get them the way you want them, and then move on to the next part.

When you are ready to move on to the next part, then you will quickly realize that your while loop goes while i is less than or equal to 10. But you never initialized i, so it starts out with a garbage number (like -858993460) and keeps adding one each time. That will take a long time to get to 10. First get the first two parts working, and then work on the third part by setting i to an intial value.

Thank you so much for your help. I've finally gotten almost everything to work now. But now I'm stuck on trying to display the sum of the squares of the odd integers.... here's the code for it.... suggestions?

When I execute what I have above, it gives me the sum of all the squares between the two numbers, not just the sum of the squares of the odds between the two numbers. I just can't figure out how to fix that.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell