Drill

ProblemsC# › billing

Early payment discount

mediumbillingMathC#

A vendor rewards early payment: the further ahead the payment, the larger the discount off the subtotal.

EarlyDiscount(subtotal: int, daysEarly: 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 EarlyDiscount(int subtotal, int daysEarly) {
    
}

Worked examples

CallResult
EarlyDiscount(10000, 10)200
EarlyDiscount(5000, 5)50
EarlyDiscount(7500, 15)150
EarlyDiscount(999, 3)0

Hint

Check the thresholds from largest to smallest.

Reference solution in C#
public int EarlyDiscount(int subtotal, int daysEarly) {
    if (daysEarly >= 10) return subtotal * 2 / 100;
    if (daysEarly >= 5) return subtotal / 100;
    return 0;
}

The same problem in another language

More billing problems in C#