dqpfkzu360216 2018-05-23 20:55
浏览 38
已采纳

PHP Pythagoras检查它是否是正确的答案

Hello i made this code below but i want it to be able to check if i guessed the answer good. If i insert 3 and 4 the answer is 5 but how do i let the code check if the answer "5" is right with the 2("3 and 4") input fields. So if all three input fields are correct. echo good and if not echo false. I am bad at explaining but i hope it's clear.

<form method="POST">
<label>Rechthoek verticaal</label>
<input name="vert"></input>
<label>Rechthoek horizontaal</label>
<input name="hor"></input>
<label>Schijne zijde</label>
<input name="schuin"></input>
<input type="submit" name="submit"></input>
</form>

<?php

if(isset($_POST['submit'])) {


$vert = $_POST['vert'];
$hor = $_POST['hor'];
$schuin = $_POST['schuin'];

$vert = pow($vert,2);
$hor = pow($hor,2);
$schuin = sqrt($vert + $hor);

echo $schuin;

}
?>
  • 写回答

2条回答 默认 最新

  • dqo88037 2018-05-23 21:08
    关注

    You need to check wheter sqrt($vert + $hor) is same as $_POST['schuin']

    <form method="POST">
    <label>Rechthoek verticaal</label>
    <input name="vert"></input>
    <label>Rechthoek horizontaal</label>
    <input name="hor"></input>
    <label>Schijne zijde</label>
    <input name="schuin"></input>
    <input type="submit" name="submit"></input>
    </form>
    
    <?php
    
    if(isset($_POST['submit'])) {
    
    
    $vert = $_POST['vert'];
    $hor = $_POST['hor'];
    $schuin = $_POST['schuin'];
    
    $vert = pow($vert,2);
    $hor = pow($hor,2);
    if ($schuin == sqrt($vert + $hor)) {
        echo "Good"; 
    }
    else {
        echo "False"; 
        echo "<br> Answer  : ".sqrt($vert + $hor);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?