C/C++ Arena

Step 2 of 6

The integer division trap

When both sides of / are int, C does integer division: the fraction is thrown away (not rounded).

printf("%d\n", 7 / 2);      // 3, not 3.5
printf("%f\n", 7.0 / 2);    // 3.500000

If either side is a double, you get a real division.

Your turn: 25 kills over 10 rounds should print Kills per round: 2.50. Right now it prints 2.00. Fix the calculation of kpr so it does a real division.

Previous: Arithmetic Next: Remainder with %