Drill

ProblemsC# › billing

Refund for partially used service

mediumbillingMathC#

A customer paid upfront but only used part of the service. Refund the unused portion.

PartialRefund(paid: int, usedUnits: int, unitPrice: 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 PartialRefund(int paid, int usedUnits, int unitPrice) {
    
}

Worked examples

CallResult
PartialRefund(1000, 40, 10)600
PartialRefund(1000, 200, 10)0
PartialRefund(500, 0, 50)500
PartialRefund(1000, 100, 10)0

Hint

Multiply usage by price, subtract from what was paid, and clamp.

Reference solution in C#
public int PartialRefund(int paid, int usedUnits, int unitPrice) {
    int cost = usedUnits * unitPrice;
    return paid > cost ? paid - cost : 0;
}

The same problem in another language

More billing problems in C#