Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use an appropriate looping statement (HTML / PHP) to write a script that prints

ID: 3820305 • Letter: U

Question

Use an appropriate looping statement (HTML / PHP) to write a script that prints a list of the Pint and Gallon equivalents of zero liters to 100 liters. When printing to the screen the results should be in a column with a heading of the names corresponding to the volumes listed underneath (you may use a table, but not required). Create a second looping statement that lists all the Pint and liters equivalents of zero Gallon to 100 Gallons. To convert liters to pints, times the number of liters by 2.1133764. To convert liters to gallons, times the number of liters by .264172052. To convert gallons to liters, times the number of gallons by 3.78521178. To convert gallons to pints, times the number of gallons by 4. Save the document as gallonConversion.php

Explanation / Answer

<html>
<head>
  <title>
  </title>
  <style>
    table {
     font-family: arial, sans-serif;
     border-collapse: collapse;
     width: 60%;
    }

    td, th {
     border: 1px solid #dddddd;
     text-align: left;
     padding: 8px;
    }

    tr:nth-child(even) {
     background-color: #dddddd;
    }
  </style>
</head>

<body>
  <table>
   <tr>
    <th>liter</th>
    <th>pints</th>
    <th>gallons</th>
   </tr>
   
    <?php
         for ($liters = 0; $liters <= 100; $liters++) {
     
      $pints = $liters*2.1133764;
      $gallons = $liters*0.264172052;
    ?>
        <tr>
      <td><?php echo $liters;?></td>
      <td><?php echo $pints;?></td>
      <td><?php echo $gallons;?></td>
     </tr>

    <?php } ?>

    
   
  </table>
  
  <table>
   <tr>
    <th>gallons</th>
    <th>liters</th>
    <th>pints</th>
   </tr>
   
    <?php
         for ($gallons = 0; $gallons <= 100; $gallons++) {
     
      $liters = $gallons*3.78521178;
      $pints = $gallons*4;
    ?>
        <tr>
      <td><?php echo $gallons;?></td>
      <td><?php echo $liters;?></td>
      <td><?php echo $pints;?></td>
      
     </tr>

    <?php } ?>

    
   
  </table>
  
  
</body>
</html>