Reputation: 45
I've written some basic messy code to solve this issue but I'm sure there must be a much better way of doing it. Here's my attempt:
$max = 17.9;
$box=0;
$x=0;
for (;;) {
if ($box > $max) break;
$box+=5;
$x++;
}
$bonus = $x-1;
echo "$bonus points added!";
So here we see that 5 fit's in to 17.9 3 times.
Upvotes: 2
Views: 168
Reputation: 219834
You made this way harder then it needed to be
$bonus = intval(17 / 5);
floor()
works here as well)Upvotes: 7