Jump to content

kr4ckl3s

New Members
  • Posts

    6
  • Joined

  • Last visited

kr4ckl3s's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I know the line causing the issue is the $Monthly += $Monthly; but I don't know what to use to correct it.
  2. Here's what I came up with to fix the percentage math issue, but now the issue is that for each iteration, the nex value of $Monthly is stored into the variable and increases it by that much each time rather than increasing by the initial amount only. The $Percentage column should display 1%, 2%, 3%, 4% etc. The $Annual Column should display $500.00, $1000.00, $1500.00, $2000.00 etc. and those two work beautifully. The final column, $Monthly is supposed to be $Ammount * $Percent/12 with $Ammount being a constant of $50,000, which it is. $Monthly is supposed to take $50,000 and multiply it by the percent of that row which it does so that on row 1 it would be $50,000 * 0.01 and then divide that by 12 (12 months in a year) to display the monthly rate, and that part works fine. But then on row 2 it's supposed to simply take the value of $Monthly and add it to itself. Then on row 3 it's supposed to take the initial value and again add to itself. Instead, it keeps re-writing the variable with the new number. I need it to do like this: (this is just an example, not the actual numerical data) 3+3=6; 6+3=9; 9+3=12 etc. Instead, it's doing this: 3+3=6; 6+6=12; 12+12=24; 24+24=48 etc. The picture I attached to this shows how it should look with correct results and all. <!--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> <h2>Yearly and Monthly Interest for $50,000 at Varying Rates</h2> <table> <tr><td>Rate</td><td>Annual Interest</td><td>Monthly Interest</td></tr> <?php // Variables $Ammount = 50000; $Annual= number_format(500,2); $Percent = 1; $Monthly = number_format($Ammount * ($Percent/100)/12,2); //For loop to display Percent, Annual and Monthly data in their respective columns for one row for ($counter = 1; $counter <= 10; $counter++) { echo "<td>$Percent%</td><td>$" . number_format($Annual, 2) . "</td><td>$" . number_format($Monthly, 2) . "</td>"; //Increments $Percent++; $Annual+=500; $Monthly += $Monthly; //Next row echo "<tr></tr>"; } ?> </table> </main> </body> </html>
  3. Oh, to concatenate it in and put in more double quotes. I didn't think it needed another set of quotes because I thought double quotes interpolate, which is why the $Percent and others could sit inside the whole thing unaffected. Awesome. The only other thing I'm trying to puzzle out is the monthly column. Any suggestions? The problem is that I need $Percent to appear as an integer like 1% 2% etc. all the way to 10% in the Percent column. Which it does. But in the $Monthly column the math I need to use is $Ammount * $Percent/12 In that case, I need the $Percent to be 0.01 because multiplying it by the integer 1 gives incorrect results. The only thing I can think of, is to create another variable for it and increase it at the bottom by 0.01 like I've done the others, but I don't know if there's a cleaner/simpler way to do it using just the one $Percent variable.
  4. <!--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= number_format(500,2); $Monthly = number_format($Ammount * $Percent/12,2); 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> The code for Monthly doesn't work right. The math only produces the same initial result the whole way down. The Annual number_format only works on the first cell in the column, the rest under it are unformatted. I've also tried foing a number_format on the increment code under the first echo with no such luck. These work, but the results are not showing up the way I need. Monthly is a logic error I'm struggling with because I need $Percent to show as an integer in the Percent column, but I need it to act as 0.01 for the math to work out correctly on the $Monthly part. I tried using this: $Annual+= number_format(500,2); for the increment part under the echo, and it didn't change anything. I tried it as $Annual number_format(=+500,2); And it crashed. Didn't really expect that one to work, but figured I'd try anyway. If I put it in the echo statement it just echo's out the actual string number_format....
  5. Yea, I've gotten the number_format funtion to work, but it doesn't seem to work in the loop. It only affects the first entry, the rest beneath it are unaffected.
  6. 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' 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. <!--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 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 calculations turn out 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 a page that will appear like the attached image. To clarify, I'm not asking anyone to do my homework. I've managed most of this thus far, but am totally stuck at this point and need help.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.