Quote:
could you help me to fix the code because it doesn't work !!
No, we can't.
We don't know what it should do, we don't know what it does do!
We aren't here to fix your homework for you - we're here to help you solve your problems. And "getting it working" is part of the task you have been set, so you are expected to debug it yourself.
Fortunately, you normally get a lot of tools to help you do that, collectively called a "debugger". Start by looking at what it happening, and working out what "it doesn't work" actually means: what does it do that you didn't expect, or not do that you did? When does it do it? What do you do to make it do that?
Then start looking at your code, and use the debugger to insert a breakpoint somewhere sensible - exactly where will depend on the "what", "when", and "what" questions above.
Then run your code in the debugger. when it reaches the breakpoint, it will stop, and let you take control. From there, you can look at variables, run your code one line at a time, and such like very useful things (exactly how you do this will depend on they development environment, but googling "debugger" and your compiler system shoudl get you a load of info).
Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!