Your code is basically correct. Please use the tag [CODE] for your code.
I have made a small modification.
Do not simply do other's homework. At the very least explain the changes. Better, just tell them what to change. They don't learn anything this way.