This is a repost, the only changes done are the corrections you have been given in first question.
I seriously donno HOW to IMPROVE THIS FURTHER[
^]
As you have already been told, use the debugger to see what your code is doing.
Your code fail because your algorithm is wrong.
As programmer,
your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.