Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm evaluating a meeting_type value that determines what kind of pricing structure I should be using. Currently, if my meeting_type value is a w, we charge one price for every 10 registrants. If the meeting_type is anything else, it's a price per registrant model.

I'm using this logic:

if($_POST['meeting_type'] != 'w'){          
    $total_price = $guests * $price;
}
else{
    $webinar_count = ceil($guests / 10);
    $total_price = $webinar_count * $price;
}

Can this logic be flawed, or improved upon?

Thanks.

share|improve this question
    
@palacsint please do not edit question with insignificant edits. –  etm124 Nov 28 '12 at 18:38

2 Answers 2

up vote 1 down vote accepted

Removing intermediate variable $webinar_count

$total_price = ($_POST['meeting_type'] == 'w')
             ? (ceil($guests / 10) * $price)
             : ($guests * $price);

OR

if ($_POST['meeting_type'] != 'w') {
    $total_price = $guests * $price;
} else {
    $total_price = ceil($guests / 10) * $price;
}
share|improve this answer
if($_POST['meeting_type'] == 'w')
    $factor = ceil($guests / 10);
else
    $factor = $guests;

$total_price = $factor * $price;
share|improve this answer
    
you are using an intermediate variable $factor that could be avoided... :) –  rajukoyilandy Nov 20 '12 at 14:54
    
'cause i am, but it's justified, it's more clearly IMHO –  huze Nov 23 '12 at 20:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.