Created
April 10, 2009 16:10
-
-
Save codatory/93140 to your computer and use it in GitHub Desktop.
PHP Function for calculating weight watcher's point values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function calculate ($calories, $fiber, $fat) { | |
$points_from_fat = $fat / 12; | |
if ($fiber = 0) { | |
$fiber_caloric_reduction = 0; | |
} elseif ($fiber < 4) { | |
$fiber_caloric_reduction = $fiber * 10; | |
} elseif ($fiber > 4) { | |
$fiber_caloric_reduction = 40; | |
} | |
if ($calories < $fiber_caloric_reduction) { | |
$calories = 0; | |
} elseif ($calories > $fiber_caloric_reduction) { | |
$calories = $calories - $fiber_caloric_reduction; | |
} | |
$result = ($calories / 50) + $points_from_fat; | |
$result = round($result); | |
return $result; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment