Drill

ProblemsC# › monitoring

What share of requests failed

easymonitoringMathC#

A status page shows the error rate as a whole percentage, because nobody reads four decimal places at a glance.

ErrorRate(errors: int, total: 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 ErrorRate(int errors, int total) {
    
}

Worked examples

CallResult
ErrorRate(5, 100)5
ErrorRate(1, 3)33
ErrorRate(2, 3)67
ErrorRate(0, 100)0

Hint

Add half the divisor before dividing, then cap.

Reference solution in C#
public int ErrorRate(int errors, int total) {
    if (total <= 0 || errors <= 0) return 0;
    return Math.Min(100, (errors * 100 + total / 2) / total);
}

The same problem in another language

More monitoring problems in C#