Kamis, 09 Oktober 2014

switch-case kalkulator

this script is switch-case in calculator
in this script i used 2 holding variable and then
use the button as arithmetic,
input the number and then process to get the result
for more information see script below and thanks to visiting



<?php
@$bil1 = $_POST['nilai1'];
@$bil2 = $_POST['nilai2'];
?>
<html>
    <body>
        <form action="#" method="POST">
            <table>
                <h1>Switch_case dengan angka</h1>
                <tr>
                    <td>Masukkan angka</td>
                    <td>:</td>
                    <td><input type="text" name="nilai1" value="<?php echo $bil1; ?>"/></td>
                    <td><input type="text" name="nilai2" value="<?php echo $bil2; ?>"/></td>
                </tr>
                <input type="submit" name="operand" value="jumlah"> <!-- tombol penjumblahan -->
                <input type="submit" name="operand" value="kurang">  <!-- tombol perkurangan -->
                <input type="submit" name="operand" value="kali">    <!-- tombol perkalian -->
                <input type="submit" name="operand" value="bagi">    <!-- tombol pembagian -->
                <input type="reset" name="reset" value="reset">      <!-- tombol reset -->
            </table>
        </form>
        <?php
        switch ($_POST["operand"]) {
            case 'jumlah':
                $hasil = $bil1 + $bil2;
                echo "Hasil Penjumlahan ", $hasil;
                break;
            case 'kurang':
                $hasil = $bil1 - $bil2;
                echo "Hasil Pengurangan ", $hasil;
                break;
            case 'kali':
                $hasil = $bil1 * $bil2;
                echo "Hasil Perkalian ", $hasil;
                break;
            case 'bagi':
                $hasil = $bil1 / $bil2;
                echo "Hasil Pembagian ", $hasil;
                break;
            default:
                echo "maaf proses perhitungan ini belum tersedia";
                break;
        }
        ?>
    </body>
</html>

Tidak ada komentar:

Posting Komentar