Which bits do you know how to write? Try to get as far as you can, and post your attempt. If you're having trouble with the logic of the program, try working out the calculations step-by-step on paper from a human perspective - this might make it easier to think about what steps the program needs to do the same, and what variables & calculations are involved.