Skip to the task
Layout
Back to classic view

You are looking at lesson 5. Your place is still lesson 11, task 1: fopen.

CHECKTask 17 of 23 · step 7: Drills: check yourself

A contract for percent

Write the contract and the assert for double percent(int part, int whole), which returns what percentage part is of whole (3 of 4 → 75.0).

Stuck?

Before: whole > 0, 0 <= part <= whole. After: a value from 0 to 100. assert(whole > 0 && part >= 0 && part <= whole); and return 100.0 * part / whole; – without 100.0 it would be integer division.