calculation of fields based on certain condition

hi dear all,

i am a beginner in sugar 

i want to do simple calculation based on certain condition

ex i have 3 integer type field

field A  (fixed value ex 100)

field B  (monthly charges ex100 per month)

field C ( no' of months)

field D ( calculate ans in this field "D" based on months. for ex. if user used only 2 month service, calculation is based on only 2 month, if user used 6 month, calculation based on 6 month. and so on,

in simple i have to sum two fields and divide into months (field A+ field B  Divided by no's months( months 1 to 12)

please suggest me a formula to solve this simple calculation