Drill

ProblemsC# › finance

Price per unit

easyfinanceMathC#

A bulk bin lists a total for a quantity of identical items. What does a single unit cost?

PricePerUnit(totalMinor: int, quantity: 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 PricePerUnit(int totalMinor, int quantity) {
    
}

Worked examples

CallResult
PricePerUnit(1000, 4)250
PricePerUnit(1000, 3)333
PricePerUnit(100, 10)10
PricePerUnit(0, 5)0

Hint

Divide and drop the remainder.

Reference solution in C#
public int PricePerUnit(int totalMinor, int quantity) {
    if (quantity <= 0) return 0;
    return totalMinor / quantity;
}

The same problem in another language

More finance problems in C#