Drill

ProblemsC++ › machines

Defects per thousand parts

easymachinesMathC++

Quality control reports scrapped parts as so many per thousand produced, truncated down.

defectsPerThousand(defects: int, produced: 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

int defectsPerThousand(int defects, int produced) {
    
}

Worked examples

CallResult
defectsPerThousand(500, 1000)500
defectsPerThousand(3, 10000)0
defectsPerThousand(1, 3)333
defectsPerThousand(2, 3)666

Hint

defects * 1000 / produced, guarding the divide by zero.

Reference solution in C++
int defectsPerThousand(int defects, int produced) {
    if (produced <= 0) return 0;
    return (defects * 1000) / produced;
}

The same problem in another language

More machines problems in C++