- a ticketing site offers a discount on "family" tickets.
- a family ticket is 2 adults, 2 children.
- the sell tickets page allows a user to enter any number of adult and child tickets.
How do I work out how to apply the family ticket discount, then charge all remaining tickets at their relevant cost (i.e. adult tickets cost more than child tickets) ?
Here's what I have so far (seems to work, but not 100% confident about it (php))
# Work out how many pairs of people there are
$numAdultPairs = floor($oForm->adult / 2);
$numChildPairs = floor($oForm->child / 2);
# work out the number of matching pairs for child / adult
if ( $numAdultPairs > $numChildPairs ) {
$numberOfFamilyTickets = $numAdultPairs - $numChildPairs;
} else if ( $numAdultPairs < $numChildPairs ){
$numberOfFamilyTickets = $numChildPairs - $numAdultPairs;
} else if ( $numAdultPairs == $numChildPairs ) {
$numberOfFamilyTickets = $numAdultPairs;
}
# work out the remaining tickets required
$remainingAdult = $oForm->adult % 2;
$remainingChild = $oForm->child % 2;