Jump to content

[SOLVED] PHP Math Help! Trying to make a quadratic calculator


nitrogen

Recommended Posts

I'm trying to convert the quadratic formula to a PHP script just to test out PHP's math handling.

I'm rather new to math in PHP  :D

Here's what I have so far:

<html>
<head><title>Quadratic Calculator</title><head>
<body>
<?php
$a = filter_input(INPUT_GET, "a"); 
$b = filter_input(INPUT_GET, "b");
$c = filter_input(INPUT_GET, "c");

$negb = -$b
$bsquare = $b * $b
$negb = $b * -1
$foura = $a * 4
$fourac = $foura * $c
$twoa = $a * 2
$numeratorend = $bsquare - $fourac
$numerator1 =$negb + $numeratorend
$numerator2 =$negb - $numeratorend
$solution1 = $numerator1 / $twoa
$solution2 = $numerator2 / $twoa
?>
<?php
print
"<p><center>
The solution(s) is/are:<br>
$solution1<br>
$solution2
</center></p>"
?>
<?php
print
"<br><br>
<p>
Variable information:
<br>a = $a
<br>b = $b
<br>c = $c
<br>bsquare = $bsquare
<br>negb = $negb
<br>foura = $foura
<br>fourac = $fourac
<br>twoa = $twoa
<br>numeratorend = $numeratorend
<br>numerator1 = $numerator1
<br>numerator2 = $numerator2
<br>solution1 = $solution1
<br>solution2 = $solution2
"
?>
</body>
</html>

 

It obtains variables a, b, and c from an HTML form. When I try to run it I get this error:

Parse error: syntax error, unexpected T_VARIABLE in /Applications/xampp/xamppfiles/htdocs/math/quadratic/calculate.php on line 10

 

Help?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.