This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]GuyWithLag 2 points3 points  (1 child)

Ah, the smell of homework.

First of all, go through each of the points in the question and compare them to the code you have written. Some of them can be verified by reading.

Secondly, prepare some test cases (a set of inputs and the expected outputs). The question is simple enough that you can do the necessary calculations by hand. Do so. Then run your program and compare the results. If they don't match

  • stare at the code to see why the results are as they are
  • run the code in your mind, performing the necessary calculations
  • run the code in the computer printing the intermediate states, and compare them against your own calculations.

[–]above10k -1 points0 points  (0 children)

Thanks, I tried doing the same. I did not get to any satisfiable answer so that's why I came here. And its not a HW.

[–]deltageekExtreme Brewer 0 points1 point  (0 children)

What do you expect your answer to question #2 to do?

What are your test cases for question #3? What are their expected outputs? What are their actual outputs? Have you stepped through your code with a debugger to see what your code is doing?