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

This is my assignment, and I have written some of the code already. I dont have

ID: 3713070 • Letter: T

Question

This is my assignment, and I have written some of the code already. I dont have issues with the HTML part but get confused as to where I should go for the rest of the PHP. I need to add a for and while loop but do not understand how to incoorporate it, I can do it without that but it is required to incoorporate that. If someone could show me the proper code with some comments on what is what that would be very helpful, thank you!

1. Write a rainfall.html file that will ask the user for 12 rainfall amounts.

2. Write a rainfall.php file that will accept these 12 values into an array.

3. Also contain the following logic: (making certain to use a loop where necessary to make code efficient)

Calculate the average rainfall.

Determine the highest rainfall amount.

Determine the lowest rainfall amount.

Display all rainfall amounts, average, highest, and lowest.

If average rainfall amount is greater than 10, display message "It was a wet season else display "It was a dry season".

3. For up to 5 additional bonus points, instead of prompting the user, have the php read an unspecified number of data values from a file. Tell me you have coded this bonus file i/o.

Since we have learned about for loops and while loops in previous chapters,make certain to use these constructs if they make you code more efficient, like we did in the classwork. Submit your rainfall.html and rainfall.php files here.

This is what I have for PHP:

<html>
<head>
    <title> Rainfall </title>
</head>
<body>
    <?php
    $january = $_POST["january"];
    $february = $_POST["february"];
    $march = $_POST["march"];
    $april = $_POST["april"];
    $may = $_POST["may"];
    $june = $_POST["june"];
    $july = $_POST["july"];
    $august = $_POST["august"];
    $september = $_POST["september"];
    $october = $_POST["october"];
    $november = $_POST["november"];
    $december = $_POST["december"];

    $monthsArray = array("$january", "$february", "$march", "$april", "$may", "$june", "$july", "$august","$september", "$october", "$november", "$december");
    $arrayLength = count($monthsArray);
    print("<p> $arrayLength </p>");
    $average = array_sum($monthsArra   

    ?>
</body>
</html>

and then for my HTML this is what I have:

<!DOCTYPE html>
<!--   -->
<html>
<head>
   <title>Rainfall Totals</title>
   <link rel ="stylesheet" type="text/css" href="sample.css">
</head>
<body>
   <!-- Set up header -->
   <h1> Rainfall Amounts </h1>
   <form action ="rainfall.php" method = "post" >

       <!-- ask user for 12 rainfall amounts -->
    <h3> Please enter 12 rainfall amounts </h3>

       <p>1: January: </p>
       <p><input size = "20" name = "january"></p>

    <p>2: February: </p>
    <p><input size = "20" name = "february"></p>

    <p>3: March: </p>
    <p><input size = "20" name = "march"></p>

    <p>4: April: </p>
    <p><input size = "20" name = "april"></p>

    <p>5: May: </p>
    <p><input size = "20" name = "may"></p>

    <p>6: June: </p>
    <p><input size = "20" name = "june"></p>

    <p>7: July: </p>
    <p><input size = "20" name = "july"></p>

    <p>8: August: </p>
    <p><input size = "20" name = "august"></p>

    <p>9: September: </p>
    <p><input size = "20" name = "september"></p>

    <p>10: October: </p>
    <p><input size = "20" name = "october"></p>

    <p>11: November: </p>
    <p><input size = "20" name = "november"></p>

    <p>12: December: </p>
    <p><input size = "20" name = "december"></p>

       <input type ="submit" value ="Calculate Rainfall">
   </form>
</body>
</html>

Explanation / Answer

I had modified the rainfall.html file and rainfall.php files according to your purpose and they are working fine as you required and you have to make sure that run these files on a local web server..

NOTE:You cant just open a php file and chek conditions on your web browser,for that you need to run in a web server.

->WAMP

->MAMP

->XAMPP

I used Xampp to run the above files thankyou....:)

//rainfall.html

<!DOCTYPE html>
<html>
<head>
<title>Rainfall Totals</title>
<link rel ="stylesheet" type="text/css" href="sample.css">
</head>
<body>
<!-- Set up header -->
<h1> Rainfall Amounts </h1>
<form role="form" action ="rainfall.php" method = "POST" >

<!-- ask user for 12 rainfall amounts -->
<h3> Please enter 12 rainfall amounts </h3>

<p>1: January: </p>
<p><input type="text" size = "20" name = "january"></p>

<p>2: February: </p>
<p><input type="text" size = "20" name = "february"></p>

<p>3: March: </p>
<p><input type="text" size = "20" name = "march"></p>

<p>4: April: </p>
<p><input type="text" size = "20" name = "april"></p>

<p>5: May: </p>
<p><input type="text" size = "20" name = "may"></p>

<p>6: June: </p>
<p><input type="text" size = "20" name = "june"></p>

<p>7: July: </p>
<p><input type="text" size = "20" name = "july"></p>

<p>8: August: </p>
<p><input type="text" size = "20" name = "august"></p>

<p>9: September: </p>
<p><input type="text" size = "20" name = "september"></p>

<p>10: October: </p>
<p><input type="text" size = "20" name = "october"></p>

<p>11: November: </p>
<p><input type="text" size = "20" name = "november"></p>

<p>12: December: </p>
<p><input type="text" size = "20" name = "december"></p>

<input id="submit" type ="submit" value ="submit" name ="submit">
</form>
</body>
</html>

//rainfall.php

<html>

<head>

<title> Rainfall </title>

</head>

<body>

<?php

$january = $_POST["january"];

$february = $_POST["february"];

$march = $_POST["march"];

$april = $_POST["april"];

$may = $_POST["may"];

$june = $_POST["june"];

$july = $_POST["july"];

$august = $_POST["august"];

$september = $_POST["september"];

$october = $_POST["october"];

$november = $_POST["november"];

$december = $_POST["december"];

$monthsArray = array("$january", "$february", "$march", "$april", "$may", "$june", "$july", "$august","$september", "$october", "$november", "$december");

$arrayLength = count($monthsArray);

$total = array_sum($monthsArray);

$maximum = max($monthsArray);

$minimum = min($monthsArray);

print("Total Rainfall Data:");

print("<br>");

foreach (array_values($monthsArray) as $i => $value) {

if($i==0){

print( "January: $value");

print("<br>");

}

if($i==1){

print( "February: $value");

print("<br>");

}

if($i==2){

print( "March: $value");

print("<br>");

}

if($i==3){

print( "April: $value");

print("<br>");

}

if($i==4){

print( "May: $value");

print("<br>");

}

if($i==5){

print( "June: $value");

print("<br>");

}

if($i==6){

print( "July: $value");

print("<br>");

}

if($i==7){

print( "August: $value");

print("<br>");

}

if($i==8){

print( "September: $value");

print("<br>");

}

if($i==9){

print( "October: $value");

print("<br>");

}

if($i==10){

print( "November: $value");

print("<br>");

}

if($i==11){

print( "December: $value");

print("<br>");

}

}

print("Total Rainfall:");

print($total);

print("<br>");

print("Average Rainfall:");

print($total/$arrayLength);

print("<br>");

print("Maximum Rainfall:");

print($maximum);

print("<br>");

print("Minimum Rainfall:");

print($minimum);

?>

</body>

</html>

The above files are working fine..!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote