2012-10-28, 08:23 PM
Rather, it seems to compare all the numbers to the very first.
Your inner loop is only exited when the end of input is reached, so prevNum never gets updated.
You don't need two loops, just one. The inner "while" should just be an "if". And "prevNum = n;" should happen at the bottom of the loop, not the top.
When you have a program like this that doesn't do what you want, you should either use a debugger to go step by step and see where things don't happen like you intended them to, or run it "by hand" - pretend you're the computer and "execute" the program according to the input.
Also, it should be "cin >> n" - I assume that's a typo, because I don't think "cin << n" would compile.
Your inner loop is only exited when the end of input is reached, so prevNum never gets updated.
You don't need two loops, just one. The inner "while" should just be an "if". And "prevNum = n;" should happen at the bottom of the loop, not the top.
When you have a program like this that doesn't do what you want, you should either use a debugger to go step by step and see where things don't happen like you intended them to, or run it "by hand" - pretend you're the computer and "execute" the program according to the input.
Also, it should be "cin >> n" - I assume that's a typo, because I don't think "cin << n" would compile.

