network monitoring
+ Reply to Thread
Results 1 to 2 of 2

Thread: Solving Quadratics with PHP

  1. #1
    Join Date
    Sep 2006
    Posts
    1,649

    Solving Quadratics with PHP

    Well, seeing how the new school year (for me) is approaching, I'm bored, and I suck at math. So I'm just gonna write up a few things in PHP to solve certain math problems for myself. Here is a simple quadratic equation solver.

    [PHP]<?php
    /****************************
    * PHP Quadratic *
    * Equation Solver *
    * Written By Moonbat *
    * July 7, 2008 *
    ****************************/

    if (isset($_POST['quadratica']) && isset($_POST['quadraticb']) && isset($_POST['quadraticc'])) {
    $a = $_POST['quadratica'];
    $b = $_POST['quadraticb'];
    $c = $_POST['quadraticc'];
    function SolveQuadratic($a, $b, $c)
    {
    echo "You provided: <b>a = $a | b = $b | c = $c </b><br><br>";
    $twoa = 2 * $a;
    $negb = 0 - $b;
    $discriminant = ($b * $b) - (4 * $a * $c);
    $sqrtdiscriminant = sqrt($discriminant);
    $finalanswerone = ($negb + $sqrtdiscriminant) / $twoa;
    $finalanswertwo = ($negb - $sqrtdiscriminant) / $twoa;

    echo "Solution #* (adding then dividing): ";
    echo "<font color=\"red\"><b>$finalanswerone</b></font>";
    echo "<br>";
    echo "Solution #2 (subtracting then dividing): ";
    echo "<font color=\"red\"><b>$finalanswertwo</b></font>";
    }
    SolveQuadratic($a, $b, $c);
    echo "<hr>";
    }

    $htmlone = "<html>
    <head><title>Quadratic Equation Solver/title></head>
    <body>
    <center><h2>Quadratic Equation Solver</h2></center>
    <center>This is a handy script to solve quadratic equations<br>
    Use the subtraction sign (-) to indicate a number is negative<br>
    If NAN is given as a solution, it indicates that the solution couldn't be expressed as a number</center>
    <br>
    <center>
    <b>Values</b>
    <form name=\"quadraticform\" method=\"POST\" action=\"$PHP_SELF\">
    a: <input type=\"text\" name=\"quadratica\"><br>
    b: <input type=\"text\" name=\"quadraticb\"><br>
    c: <input type=\"text\" name=\"quadraticc\"><br><br>
    <input type=\"Submit\" value=\"Submit\">
    </form></center>
    </body>
    </html>";
    echo $htmlone;
    ?>[/PHP]
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

  2. #2
    Join Date
    Sep 2006
    Posts
    1,649
    How do you get a plus&minus sign to work? Too bad PHP doesn't have anything like that (as far as I know).

    And it's better to be a Python fanboy than a Java fanboy.
    "Workers of the world unite; you have nothing to lose but your chains." -Karl Marx

+ Reply to Thread

Similar Threads

  1. [PHP] Solving Euler Project #2
    By Moonbat in forum Programming
    Replies: 1
    Last Post: 07-24-2008, 04:36 PM
  2. [PHP] Solving Euler Project #*
    By Moonbat in forum Programming
    Replies: 1
    Last Post: 07-13-2008, 04:38 PM
  3. Solving a Major Firewall Hole in many Web Browsers
    By Unregistered in forum Viruses and Trojans
    Replies: 0
    Last Post: 07-03-2003, 08:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts