Drill

ProblemsC# › pricing

Loyalty points for a basket

easypricingMathC#

The card scheme awards one point for every full ten lira spent, and doubles that on promotion days.

PointsFor(spend: int, doubleDay: bool) → 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 PointsFor(int spend, bool doubleDay) {
    
}

Worked examples

CallResult
PointsFor(10000, false)10
PointsFor(10999, false)10
PointsFor(10000, true)20
PointsFor(999, false)0

Hint

Integer-divide by 1000, then double if the flag is set.

Reference solution in C#
public int PointsFor(int spend, bool doubleDay) {
    if (spend <= 0) return 0;
    int earned = spend / 1000;
    return doubleDay ? earned * 2 : earned;
}

The same problem in another language

More pricing problems in C#