dongpao1905 2015-06-22 21:01
浏览 77

根据性别和身高计算理想体重。 我们如何将int转换为英寸?

The calculation for the "female" option is found by multiplying her height in inches by 3.5 and subtracting 108. The calculation if "male" is selected will be found by multiplying his height in inches by 4 and subtracting 128. I am not sure how to translate this into a php function. This calculation is processed upon pushing a submit button. My goal is to calculate the ideal weight of the given gender and height.

Currently I am unable to display the $result. Does anyone see my error?

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);
?> 
<?php
if(isset($_POST['submit'])) {

$gender = isset($_POST['gender']) ? $_POST['gender']: 0;
$height = (int)$_POST['height'];

switch ($gender) {

    case 2:
        $result = ($height * 3.5) - 108;
        break;

    case 1:
        $result = ($height * 4) - 128;
        break;

    default:
        $result = 0;
}

echo "Ideal Weight:", $result;
}
?> 

<html>
<div align="center">
<body>
    <form name="form" method="post" action="<?php echo $PHP_SELF;?>">
        Select Your Gender: <select name="gender">
            <option value=""></option>
            <option value="1">Male</option>
            <option value="0">Female</option>
        </select>
        <br><br>
        Enter Your Height: <input type="number" name="height">
        <br><br>
        <input type="submit" name="submit" value="Calculate"/>
    </form>
</body>
</div>
</html>
  • 写回答

2条回答 默认 最新

  • dongqiangse6623 2015-06-22 21:10
    关注

    Try this:

    <?php
    if(isset($_POST['submit'])) {
        $gender = isset($_POST['gender']) ? $_POST['gender']: 0;
        $height = (int)$_POST['height'];
        switch ($gender) {
            case 1:
                $multiplier = 3.5;
                $substract = 108;
                break;
            case 0:
            default:
                $multiplier = 4;
                $substract = 128;
                break;
        }
    
        $result = ($height * $multiplier) - $substract;
        //Do whatever you want to do with $result
    }
    ?>
    

    This is just a rough example, conversion to inches is not done, it's only to show a way to calculate the result.

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效