Drill

ProblemsC# › billing

Calculate tax on a shipping charge

easybillingMathC#

Some regions tax shipping, others do not. Compute the tax amount on a shipping cost.

TaxOnShipping(shippingCost: int, taxPercent: int, taxable: 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 TaxOnShipping(int shippingCost, int taxPercent, bool taxable) {
    
}

Worked examples

CallResult
TaxOnShipping(8000, 10, true)800
TaxOnShipping(8000, 10, false)0
TaxOnShipping(0, 20, true)0
TaxOnShipping(5500, 8, true)440

Hint

One conditional and an integer division.

Reference solution in C#
public int TaxOnShipping(int shippingCost, int taxPercent, bool taxable) {
    if (!taxable) return 0;
    return shippingCost * taxPercent / 100;
}

The same problem in another language

More billing problems in C#