Drill

ProblemsC# › billing

Prorate an annual subscription refund

mediumbillingMathC#

When a subscriber cancels early, the unused portion of the annual fee is refunded proportionally.

ProrateRefund(annualAmount: int, monthsUsed: int) → int

C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

public int ProrateRefund(int annualAmount, int monthsUsed) {
    
}

Worked examples

CallResult
ProrateRefund(12000, 0)12000
ProrateRefund(12000, 12)0
ProrateRefund(12000, 3)9000
ProrateRefund(10000, 5)5833

Hint

Clamp first, then multiply before dividing.

Reference solution in C#
public int ProrateRefund(int annualAmount, int monthsUsed) {
    int m = Math.Max(0, Math.Min(12, monthsUsed));
    return annualAmount * (12 - m) / 12;
}

The same problem in another language

More billing problems in C#