I've created some code that provides information about a given quadratic equation (because I HATE repetitive, time-consuming things). However, it only accepts input in decimal form, and only gives output in decimal form. I need it to be able to accept fraction inputs and to give a fraction if the output is not a whole number. I cannot provide a working link, as I am simply running it on my home computer for personal use, but here is the code:
Code: Select all
<?
// Has the user provided input?
if (!isset($_GET['submit'])) {
// No
// Input page
?><html>
<head>
<title>Quadratic Equation Table Maker XTREME!</title>
</head>
<body>
<center>
<h1>Quadratic Equation<br>Table Maker XTREME!</h1>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="get"><i>y</i>=<input type="text" size="2" value="a" name="a"><i>x</i><sup>2</sup>+<input type="text" size="2" value="b" name="b"><i>x</i>+<input type="text" size="2" value="c" name="c"><br><br><input type="submit" value="Make Table" name="submit"></form>
</center>
</body>
</html><?
}
else {
// Yes
// Get variables
$a = $_GET['a'];
$b = $_GET['b'];
$c = $_GET['c'];
// Idiot check
if(!is_numeric($a) || $a == '0') { echo '<center><h1>The input "'.$a.'" for <i>a</i> is not valid.</h1></center>'; }
if(!is_numeric($b)) { echo '<center><h1>The input "'.$b.'" for <i>b</i> is not valid.</h1></center>'; }
if(!is_numeric($c)) { echo '<center><h1>The input "'.$c.'" for <i>c</i> is not valid.</h1></center>'; }
if(!is_numeric($a) || !is_numeric($b) || !is_numeric($c) || $a == 0) { echo '<center><h1>You suck at numbers.<br>Try again:</h1><form action="'.$_SERVER['PHP_SELF'].'" method="get"><i>y</i>=<input type="text" size="2" value="a" name="a"><i>x</i><sup>2</sup>+<input type="text" size="2" value="b" name="b"><i>x</i>+<input type="text" size="2" value="c" name="c"><br><br><input type="submit" value="Make Table" name="submit"></form>'; die(); }
// Calculate x values
$vertex = (-($b)) / (2 * ($a));
$minus3 = $vertex - 3;
$minus2 = $vertex - 2;
$minus1 = $vertex - 1;
$plus1 = $vertex + 1;
$plus2 = $vertex + 2;
$plus3 = $vertex + 3;
// Display output page
?><html>
<head>
<title>Quadratic Equation Table Maker XTREME!</title>
</head>
<body>
<center>
<h1>Quadratic Equation<br>Table Maker XTREME!</h1>
<? echo '<i>y</i>='.$a.'<i>x</i><sup>2</sup>+'.$b.'<i>x</i>+'.$c; ?><br>
<br>Graph opens <? if($a > 0) { echo 'UP'; } else { echo 'DOWN'; } ?>.<br>Vertex: (<? echo $vertex; ?>, <? echo (($a) * $vertex * $vertex) + (($b) * $vertex) + ($c); ?>)<br>Axis of symmetry: <i>x</i>=<? echo $vertex; ?><br><br>
<table border="1" cellpadding="3">
<tr>
<th><i>x</i></th>
<th><i>y</i></th>
<th>Substitution</th>
</tr>
<tr>
<tr>
<td><? echo $minus3; ?></td>
<td><? echo (($a) * $minus3 * $minus3) + (($b) * $minus3) + ($c); ?></td></td>
<td><? echo $a.'('.$minus3.')<sup>2</sup>+'.$b.'('.$minus3.')+'.$c; ?></td>
</tr>
<tr>
<td><? echo $minus2; ?></td>
<td><? echo (($a) * $minus2 * $minus2) + (($b) * $minus2) + ($c); ?></td></td>
<td><? echo $a.'('.$minus2.')<sup>2</sup>+'.$b.'('.$minus2.')+'.$c; ?></td>
</tr>
<tr>
<td><? echo $minus1; ?></td>
<td><? echo (($a) * $minus1 * $minus1) + (($b) * $minus1) + ($c); ?></td></td>
<td><? echo $a.'('.$minus1.')<sup>2</sup>+'.$b.'('.$minus1.')+'.$c; ?></td>
</tr>
<tr>
<td><? echo $vertex; ?></td>
<td><? echo (($a) * $vertex * $vertex) + (($b) * $vertex) + ($c); ?></td></td>
<td><? echo $a.'('.$vertex.')<sup>2</sup>+'.$b.'('.$vertex.')+'.$c; ?></td>
</tr>
<tr>
<td><? echo $plus1; ?></td>
<td><? echo (($a) * $plus1 * $plus1) + (($b) * $plus1) + ($c); ?></td></td>
<td><? echo $a.'('.$plus1.')<sup>2</sup>+'.$b.'('.$plus1.')+'.$c; ?></td>
</tr>
<tr>
<td><? echo $plus2; ?></td>
<td><? echo (($a) * $plus2 * $plus2) + (($b) * $plus2) + ($c); ?></td></td>
<td><? echo $a.'('.$plus2.')<sup>2</sup>+'.$b.'('.$plus2.')+'.$c; ?></td>
</tr>
<tr>
<td><? echo $plus3; ?></td>
<td><? echo (($a) * $plus3 * $plus3) + (($b) * $plus3) + ($c); ?></td></td>
<td><? echo $a.'('.$plus3.')<sup>2</sup>+'.$b.'</i>('.$plus3.')+'.$c.'</i>'; ?></td>
</tr>
</table><br>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="get"><i>y</i>=<input type="text" size="2" value="a" name="a"><i>x</i><sup>2</sup>+<input type="text" size="2" value="b" name="b"><i>x</i>+<input type="text" size="2" value="c" name="c"><br><br><input type="submit" value="Make Table" name="submit"></form>
</center>
</body>
</html><?
}pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: