Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = <<<END
- 67.5 150
- 64 160.0
- 74.00000000 200
- 100 205
- END;
- //Weight in kilograms - Height in centimeters
- $input = explode("\n", $input);
- foreach($input as $key => $value){
- $line = explode(" ", $value);
- $weight = $line[0];
- $height = $line[1];
- $height_m = intval($height)/100;
- if($height != 0){
- $bmi = round($weight/pow($height_m, 2), 1);
- }
- if($bmi > 30){
- $weight_status = "Obese";
- }elseif($bmi > 25){
- $weight_status = "Overweight";
- }elseif($bmi >= 18.5){
- $weight_status = "Normal";
- }else{
- $weight_status = "Underweight";
- }
- $out_weight = str_pad(number_format(round($weight, 1), 1)."kg", 8, " ", STR_PAD_RIGHT);
- $out_height = str_pad(round($height)."cm", 7, " ", STR_PAD_RIGHT);
- $out_bmi = str_pad("BMI=".number_format(round($bmi, 1), 1), 10, " ", STR_PAD_RIGHT);
- if(count($input)-1 != $key){
- //add newline to end of print
- print $out_weight.$out_height.$out_bmi.$weight_status."\n";
- }else{
- //print without appended new line
- print $out_weight.$out_height.$out_bmi.$weight_status;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment