I can only use one page and have to use PHP and html in order to make a table using a for loop to increment three different columns. The first column is 'Rate' the second is 'Annual Interest' and the third is 'Monthly Interest'
PURPOSE: Practice in writing calculations and loops and in embedding HTML inside a PHP tag
PROCEDURE: In this lab you will write a php program that will calculate the annual and monthly interest on a loan. There will be no HTML page and no form. The program will use a loop to calculate the annual and monthly interest rate on 50000 dollars for every interest rate from 1 to 10 ( 1 being 1% APR (annual percentage rate). Format the results to display dollar signs and two decimal places. Display all the data in an HTML table (see provided jpeg). The code must have variables for the interest rate, annual interest and monthly interest and must define a constant named AMOUNT that will have a value of 50000.
Annual interest on a loan is calculated by multiplying the loan amount by the annual interest rate (expressed as a decimal – if the annual Interest rate is 1 percent the formula will multiply 50000 by .01.
Monthly interest can be calculated by dividing the annual interest by 12. Write a program that will calculate the annual and monthly interest for $50,000 at annual rates from 1 to 10 percent in increments of 1 percent and output the results as a table. You may use any type of loop you choose.HINTS: The first few lines in the php tag will declare your variables. To create a table, you use echo statements and place the HTML inside of single quotes. For example, this code, inside a php tag, will create and display a paragraph element:
echo '
Hello World!
';You will need to indicate the start of a table outside your loop. You will create the first row of the table outside the loop. The rest of the rows will be created inside of a loop that uses a counter going from 1 to 10. Inside each iteration the loop you will calculate the annual and monthly interest on 50000 using the counter, storing the answers in your variables and displaying the info in a row of the table. The ending tag for the table will be after the loop.
Provide a CSS file that will at a minimum will format the table.
Yea, it's a class assignment and unfortunately the class only meets once per week and the professor doesn't really specialize in this subject matter, but a recent surge in enrollment has stretched the faculty kinda thin and she's virtually unavailable. We've only had two classes thus far, and I'm still pretty new to PHP.
*************EDIT*************
<!--Indicates page is HTML5 compliant-->
<!DOCTYPE html>
<html>
<head>
<!--Titles the page at the top such as on the browser tab (w/ Chrome)-->
<title>Monthly & Yearly Interest</title>
<!--Pulls the CSS styling from the main.css page-->
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<main>
<p>Yearly and Monthly Interest for $50,000 at Varying Rates</p>
<table border="1">
<tr><td>Rate</td><td>Annual Interest</td><td>Monthly Interest</td></tr>
<?php
$Ammount = 50000;
$Percent = 1;
$Annual= 500;
$Monthly = $Ammount * $Percent/12;
for ($counter = 1; $counter <= 10; $counter++) {
echo "<td>$Percent%</td><td>$$Annual</td><td>$$Monthly</td>";
$Percent++;
$Annual+=500;
//$Monthly = ;
echo "<tr></tr>";
}
?>
</table>
</main>
</body>
</html>
I've updated my code and cleaned it up. Thank you for all the help. I'm still having an issue with this though. I've tried using $Annual = number_format(500,2);
and also modified the increment counter below the echo to do likewise, but I can only get the number formatting to appear on the first row. Also having a similar issue with the $Percent
value. Technically I need the percent value to be 0.01 for the $Monthly
calculation to be correct, but I need the $Percent value to appear as a whole digit in the first column. I'm trying my best to explain this clearly. I have to use a for loop and have to follow the above instructions in order to create this: