The amount you’re charged is a combination of the depreciation fee and the finance fee.
The depreciation fee has a formula of:
Depreciation Fee = (Net Cap. Cost - Residual Value)/Months
As you don’t seem to have any residual value for the vehicle, I can assume that the car will not be returning and thus has a residual value of 0.
The finance fee is applied to the depreciation fee where the money factor can be worked out from the annual percentage rate:
Finance Fee = (Net Cap. Cost + Residual Value) * (APR / 2400)
In regard to your code, this would be:
var depreciationFee = (amount - downpayment) / months;
var financeFee = (amount + downpayment) * (interest / 2400);
var result = depreciationFee + financeFee;
Further details can be found at the annual percentage rate wiki page.