> is this right ?

Well, does it work as you want? If not then it's not right. If it does then it is right.
Have you tried compiling it?
Did you get any errors?

Programming is very much about doing stuff yourself. If you're so stuck that you can't even plug code into a compiler then I would suggest you're way out of your depth already and should consider getting some extra tuition outside class otherwise you're never going to make it.