Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_POST["calc"])){
- $fn = $_POST["num1"];
- $sn = $_POST["num2"];
- $op = $_POST["operation"];
- switch ($op){
- case "+": $result = $fn + $sn; break;
- case "-": $result = $fn - $sn; break;
- case "*": $result = $fn * $sn; break;
- case "/": $result = $fn / $sn; break;
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Калкулатор</title>
- </head>
- <body bgcolor="#23ff77">
- <form method="post" action="#">
- <table border="1" align="center">
- <tr>
- <td colspan="2" align="center">
- <h3>КАЛКУЛАТОР - PHP</h3>
- </td>
- </tr>
- <tr>
- <td>
- Въведи първото число:
- </td>
- <td>
- <input type="text" name="num1">
- </td>
- </tr>
- <tr>
- <td>
- Въведи второто число:
- </td>
- <td>
- <input type="text" name="num2">
- </td>
- </tr>
- <tr>
- <td>
- Избери операция:
- </td>
- <td align="center">
- <select name="operation">
- <option value="+">+</option>
- <option value="-">-</option>
- <option value="*">*</option>
- <option value="/">/</option>
- </select>
- </td>
- </tr>
- <tr>
- <td colspan="2" align="center">
- <input name="calc" type="submit" value="ПРЕСМЕТНИ">
- </td>
- </tr>
- <tr>
- <td>
- Резултат:
- </td>
- <td>
- <?php
- if (isset($result)){
- echo $result;
- }
- ?>
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement