Please check some of my math seems messed

Hello! Im new to this board I posted earlier today and have been working on this program all day. I think I have it done. The program runs a few calculations then asks for some dimensions and then it does one last calculation. The math im not sure of is the amount of pools needed. the equation is to be volume of a grain ofwheat(20mm3) * amount of wheat/ volume of pool. I believe I have everything set right and I know im dealing with some large numbers, but the pool amount just seems too much
heres my code:

<?php if (isset($_POST['submit'])) { // calculate the volume calcVol(); } //display the form displayForm(); /*********************************************************/ // define a function to calculate the volume function calcVol(){ // read the input $length = $_POST['length']; $width = $_POST['width']; $height = $_POST['height']; $rice = 1; for ($square = 1; $square <= 63; $square++) { $rice *= 2;} $weight = $rice*50; $vol = $length*$width*$height; $needed = ($rice*20)/($vol*1000);/*this is the variable and formula please check! Its supposed to determine the amount of pools needed to hold the volume of wheat we have . its supposed to be pools= (volume of grain of wheat)*(amount of wheat)/(volume of pool which is originally in m so i convert it to mm.*/ /* Requirement: length, width and height must be nonnegative integers */ if (!is_numeric($length) || $length <20 || $length >50 || intval($length) != floatval($length)){ echo "Invalid length!"; } else if (!is_numeric($width)|| $width < 5|| $width >15 || intval($width) != floatval($width)) { echo "Invalid width!"; } else if (!is_numeric($height)|| $height < 3 || $height >6 || intval($height) != floatval($height)) { echo "Invalid height!"; } else { //calculate the volume // Display the result echo "Pool Dimensions and Volume:
\n"; echo "Length: ".$length."m
\n"; echo "Width: ".$width."m
\n"; echo "Height: ".$height."m
\n"; echo "Volume: ".$vol."m3
\n"; echo "
\n"; echo "The Inventor received " . number_format($rice) . " grain(s) of wheat.
"; echo "The wheat weighs: ". number_format($weight). " mg.
"; echo "The amount of pools needed: ". number_format($needed). ".
"; } } // end calcvolume function displayForm(){ ?>
    <!--  display html content  -->
    <h2>Calculate pool volume</h2>
    <form method="post" action="assignment2.php" >
    <table border="0">
       <tr><td>Length:</td><td><input type="text" name="length" /></td></tr>
       <tr><td>Width: </td><td><input type="text" name="width" /></td></tr>
       <tr><td>Height: </td><td><input type="text" name="height" /></td></tr>

    <p><input type="submit" name="submit" value="Calculate" />
       <input type="reset"  name="reset" value="Clear" /></p>
<?php // back to php mode to end the function }// end displayForm ?>


I don’t understand this… What does this mean to you? To mean it means you are doing a loop 62 tims

Making the rice number really large 2^63 power…

[php]for ($square = 1; $square <= 63; $square++)

$rice *= 2;}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service