UPDATE: Apparently, people think this is a homework assignment and are down voting my question. It's not. It's a re-life business logic question which is pretty complicated math as you can see from the answer. I would appreciate a little positive votes so I can continue to use this site.
I need to figure out a formula for a free nights calculator. The free nights options can vary. For example pay for 6, stay for 7. Pay for 5, stay for 7.
Given the two numbers in the variable, I need to be able to pass the number of nights, and calculate the number you pay for and the number you get free.
For example:
Pay for 5, stay for 7.
1 night = pay for 1, 0 free
2 nights = pay for 2, 0 free
3 nights = pay for 3, 0 free
4 nights = pay for 4, 0 free
5 nights = pay for 5, 0 free
6 nights = pay for 5, 1 free
7 nights = pay for 5, 2 free
8 nights = pay for 6, 2 free
9 nights = pay for 7, 2 free
10 nights = pay for 8, 2 free
11 nights = pay for 9, 2 free
12 nights = pay for 10, 2 free
13 nights = pay for 10, 3 free
14 nights = pay for 10, 4 free
15 nights = pay for 11, 4 free
16 nights = pay for 12, 4 free
17 nights = pay for 13, 4 free
18 nights = pay for 14, 4 free
I was thinking I needed to use modulus, but could not figure it out.
$pay_for = 5;
$stay_for = 7;
for($i=1;$i<=18;$i++) {
$modulo = $i % $pay_for;
echo("nights:{$i}, remainder:{$modulo}<br>\n");
}
Thanks for any help!
EDITED: Left out a line in my examples above so updated.