Drill

ProblemsC# › billing

How much is still owed

easybillingArraysMathC#

Compare the amount due against a list of payments already received and return the shortfall.

BalanceShortfall(due: int, payments: list<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 BalanceShortfall(int due, List<int> payments) {
    
}

Worked examples

CallResult
BalanceShortfall(10000, new List<int> { 3000, 4000 })3000
BalanceShortfall(5000, new List<int> { 5000 })0
BalanceShortfall(5000, new List<int> { 6000 })0
BalanceShortfall(1000, new List<int> { })1000

Hint

Sum the payments and subtract from due.

Reference solution in C#
public int BalanceShortfall(int due, List<int> payments) {
    int paid = 0;
    foreach (int p in payments) paid += p;
    return Math.Max(0, due - paid);
}

The same problem in another language

More billing problems in C#