Show DevBest [PHP] Another calculator

Status
Not open for further replies.

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
I don't know why but it's something about calculators that I like.
This is the 5th one I've made. I took m0nsta.'s suggestion and tried to make it easier to read the code.
Although there's not much of it.
Calc.php
PHP:
<?php
$num1 = $_POST['number1'];
$num2 = $_POST['number2'];
$methood = $_POST['meth'];
 
    if($methood == 1) {
                        $a = $num1 + $num2;
                        echo $a;
    } elseif ($methood == 2) {
                        $a = $num1 - $num2;
                        echo $a;
    } elseif ($methood == 3) {
                        $a = $num1 / $num2;
                        echo $a;
    } elseif ($methood == 4) {
                        $a = $num1 * $num2;
                        echo $a;
    } elseif ($methood == 5) {
                        echo pow($num1, $num2) ;
    } else {
    echo 'Something went wrong! Please go back and try again!';
    }
//Hope this worked out for you!
?>

Index.html
HTML:
<html>
    <head>
        <title>Calculator</title>
    </head>
    <body>
        <form action="calc.php" method="POST" >
            First number: <input type="text" name="number1"><br />
            Second number: <input type="text" name="number2"><br />
            <p>What to do?</p>
            <input type="radio" name="meth" value="1" />Add (First number add the Second)<br />
            <input type="radio" name="meth" value="2" />Subtract (first number Subtracted by the second<br />
            <input type="radio" name="meth" value="3" />Divide (First number divided by the second)<br />
            <input type="radio" name="meth" value="4" />Multiply (First number times the Second number)<br />
            <input type="radio" name="meth" value="5" />Exponent (First number is the base, second is the power!)<br />
            <input type="submit" value="calculate"
        </form>
    </body>
</html>

Hope you liked it.
Feel free to suggest anything :D



Screenshots as requested by Vineen:
iSP8Cl.png

Answer:
7vitIK.png
 

Adidas

Retro Developer
May 6, 2012
296
19
Good idea just needs to be edited. Would look better if it was more compact and had a css to it ;)
 
Status
Not open for further replies.

Users who are viewing this thread

Top