Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="" method="post">
- <input type="number" name="num1" placeholder="Enter the first number"><br><br>
- <input type="number" name="num2" placeholder="Enter the second number"><br><br>
- <input name="calculation" type="submit" value="Calculate"><br><br>
- </form>
- <?php
- class Calculator
- {
- public function add($num1, $num2)
- {
- echo "Summation: " . ($num1 + $num2) . "<br>";
- }
- public function deduct($num1, $num2)
- {
- echo "Deduction: " . ($num1 - $num2) . "<br>";
- }
- }
- if(isset($_POST['calculation'])){
- $num1 = $_POST['num1'];
- $num2 = $_POST['num2'];
- if(empty($num1) || empty($num2)){
- echo "<p style='color:#ee6554'>Fields can not be empty!</p>";
- } else {
- $calc = new Calculator();
- $calc->add($num1, $num2);
- $calc->deduct($num1, $num2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement