Jump to content

kakes

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Everything posted by kakes

  1. Thanks. Maybe I can figure out the rest. You've been a big help and I appreciate it.
  2. I'm still working on this. I think it's in my foreach statement but I'm not sure.
  3. Sorry. My array does not display like it should in a browser. I need it to display the day of the week, the item and the price. I need to explode the array where the item and price is joined by a colon ":". I don't think I have the explode() quite right. Would someone mind taking a look? There are other issues, also, but I'm such a noobie and have no idea what the issues could be. I hope this explains better what I need help with. Thank you again.
  4. My code doesn't work and I don't know what I did wrong. :'(
  5. Hello all!! I need help with an associative array I've been working on. I'm not sure if I should have typed the weekday in the index because I'm supposed to use the getdate() function to pull the day of the week into the array. I'm also supposed to use string functions to pull apart the value where it's connected with the colon ":". I've tried using explode() and strtok but I don't quite understand how they work...just like the getdate()..I don't understand. Thanks for any 'nudge' in the right direction you can offer. <?php $title = "Associative Array"; $heading = "Daily Specials"; $specials = array( "Sunday" =>"52in Flat Screen TV:425.00", "Monday" =>"Amplifier:145.00", "Tuesday" =>"HP Computer:355.00", "Wednesday" =>"500GB External Harddrive:99.00", "Thursday" =>"Internal Speakers:55.00", "Friday" =>"Ergonomic Keyboard:85.00", "Saturday" =>"Wacom Tablet:175.00", ); echo "<html> <head> <title> $title </title> </head> <body> <h1> $heading </h1> <pre>\n"; //prints left and right aligned headers with 30 spaces printf ("%-30s%30s\n", "Items", "Price"); printf ("%'-60s\n", ""); foreach ($specials as $key=>$value); { //prints the key left aligned and the value right aligned //formats to two decimals spaces printf ("%-20s%20.2f\n", $key, $value); echo " </pre>\n"; $delimeter=":"; $inventory=strtok($inventory,$delimeter); while(is_string($inventory)) { if($inventory) { echo " $inventory\n"; } $inventory=strtok($delimiter); } $inventory=explode($delimeter,$inventory); foreach ($items as $item=>$price) { echo" $item, $price\n"; } echo " </pre>\n"; "</body> </html>\n"; ?>
  6. I think I've got it figured out, with your help of course! Thanks for helping!!
  7. I've been working on this as you'll see but it still doesn't work quite right. Any suggestions? Thanks!! <?php // variables $diameter = 6; $pi = 3.14; $area = ($diameter * $pi); $title = "Circle"; function circle_area($num,$type="radius") { if(is_numeric($num) && is_string($type) && !empty($num) && !empty($type)) { $radius = ($type == "diameter") ? $num/2 : $num; // Radius is set to half the given number if the type is diameter, or unchanged if radius $area = pi()*pow($radius,2); // Pi as defined by php multiplied by radius to the power of 2 (squared) return $area; // Return result } else { return -1; // Return Pi when invalid/empty values are given } } echo "<html> <head> <title> $title </title> </head> <body> <h1>Area of a Circle</h1>\n"; echo circle_area(6,"diameter"); echo "</body> </html>"; ?> I know, I need to clean up my code.
  8. I'm probably overcomplicating it like I do everything else. Thank you for your help. Your example calculates like I need it to. I hope I can wrap my brain around this soon.
  9. I just don't understand what I'm supposed to do. I went by an example but, apparently, I didn't quite get what it was all about. Thanks for looking.
  10. Okay, I've worked really hard on this and almost have it. There's just one small thing that I can't get to work right. Here's my new code. :-\ <?php function circleArea($total, $area, $diameter) { // Calculate area of circle or returns a -1 if area is not diameter x pi if ($area == "Area") { $answer = $diameter * $pi; $answer .= "Area"; } elseif ($radius == "Diameter") { $answer = $raduis * $radius; $answer .= "Diameter"; } else { $answer = -1; } return $answer; } $title = "Calculate Area of Circle"; $diameter=4.0; $radius=2.0; $pi=3.14; $total=$diameter * $pi; $total = circleArea($area, "Total", $diameter); $area = circleArea($total, "Area", $area); $error = circleArea(1, "Stuff", 10); echo "<html> <head> <title> $title </title> </head> <body> <h1> $title </h1> <h3> If the diameter of a circle is $diameter the total area is $total. </h3> </body> </html>\n"; ?>
  11. Is it that bad? I've been working on this for days and I'm going nuts. Maybe it'll click for me soon. :'(
  12. Hello all! Got another code that I need a helpful nudge with. I need to create a function to calculate the area of a circle. The function has to take in two arguments (a number and a string). The number is the diameter; the string is the word "diameter." The function has to return the area of the circle or a -1 for an error. The script has to initialize test variables, call the function and display the results. I'm such a noob so don't laugh when you see my code thus far. I appreciate any help you can offer. <? php // variables $diameter = 4.0; $pi = 3.14; $area = ($diameter * $pi); $title = "Circle"; function circle_function (4.0, "diameter") if ($diameter * $pi) !=$area) { return $area; } { else return -1; } if ($area == -1) { echo "Invalid input"; exit -1; } echo "<html> <head> <title> $title </title> </head> <body> <h1>Area of a Circle</h1>\n"; echo circle_function(); echo "</body> </html>"; ?>
  13. Thanks so much for your help! To answer your question, I keep changing code because I'm not sure what I'm doing. I try one approach, then another, just to see which one is going to work the best. The only thing now I need to work on is getting the dollar amounts to increase by 50 cents instead of one dollar and also use "round" to round the dollar amounts to the nearest cent. I'm sure it's a matter of tweaking the code so hopefully I can figure it out. Sure hope so!! Thanks again!!
  14. I've taken yet another approach to this table. I think I'm almost there but I can't get the zeros to show up and I can't figure out where to put the round() to make the dollar amounts round to the nearest cent. I would also like the $ and % signs to print but am not sure where to echo them. Thanks for any help you can offer! Here's my new approach.. <?php // variables $title = "Discount Table"; $maxSize= 20; echo "<html> <head> <title> $title </title> <!-- Embedded style sheet --> <style type=\"text/css\"> th,td {border: 1px solid black; width: 25px; padding: 4px; text-align: center;} </style> </head> <body> <h1> $title </h1> <table style=\"border: 1px solid black;\"> <tr> <th></th>\n"; for ($columnHeading=1.00; $columnHeading <= $maxSize; $columnHeading++) { echo " <th>$columnHeading</th>\n"; } echo " </tr>\n"; for ($row = .05; $row <= 1.00; $row+=.05) { echo " <tr>\n"; echo " <th>$row</th>\n"; for ($column = 1; $column <= $maxSize; $column++) { $total = $column * $row; echo " <td>$total</td>\n"; } echo " </tr>\n"; } echo " </table> </body> </html>\n"; ?>
  15. That's great! Just one thing: how do I get the dollar amount to start at $1.00 and increase 50 cents each column and reflect the discount in the table...sort of like a multiplication table? You've been such a great help and I certainly appreciate it!
  16. Thank you!! That did generate my table and I can view it now. It's not calculating like I need it to and I also need to round to the nearest cent. What I need it to do is this: The table increases the discount rate by 5% up to 95%. I think it is mostly doing that on the left side (need to add a percent sign). I was trying to get the amount to start at a dollar and increase by 50 cents. The table is supposed to calculate the dollar amount with the discount and display it across the rows like a multiplication table. I need 20 rows/columns. Any help is certainly appreciated!
  17. I've taken a different approach to this but I'm not sure it will work. I can't get it to load so I can't view it. Must be something wrong. Help. <?php echo "<table style=\"border: 1px solid black;\"> \n"; for ($discount = 5; $discount<=95; $discount+5) { echo "<tr>\n"; for ($amount = 1.00; $amount<=10.50; $amount+.50) { echo "<td style=\"border: 1px solid #000; width: 25px; padding: 4px; text-align: center;\">"; echo ($discount * $amount); echo "</td>\n"; } echo "</tr>\n"; } echo "</table>"; ?>
  18. Welcome, Marius. I'm new, too. Hope we learn a lot!
  19. I'm new, too, and trying to learn this php stuff. This seems like a good place to start!
  20. I too am a php beginner. Welcome!!
  21. I've got a lot riding on my ability to be able to understand php and complete my assignments. I did great in my html, xhtml class last semester but am getting confused with php and how to tie the two together to get the desired results. I'm not asking for anyone to do my assignments, just give me a little nudge in the right direction. If I can't pass this class, I don't graduate in May. I'm out of work and have been for going on two years. I have an opportunity to work and teach at a local community college, but I have to have my degree in hand before they will hire me. That's my story, sad but true. Thanks again for all your help. I'm so glad I found this site. It's has been a great blessing so far.
  22. Thanks, I've got a lot of work to do on this so I appreciate you guys steering me in the right direction.
  23. Sorry. Wasn't sure where to post the question.
  24. I need help again. I need to create a discount table. The table should increase the discount rate by 5% and the amount by 50 cents each time. I have to have 20 rows of data. The discount rate starts at 5% and goes up to 95%. Row headings and column headings have to be bold. All dollar values have to be rounded using round(). I think I have the table headings correct except I have the amount increasing by 50 not 50 cents. I don't understand what I need to do in order to have the table generate the discount rate. Here's my code so far. <?php $original_price = 5; echo "<table border=\"1\" align=\"center\">"; echo "<tr><th>Amount</th>"; echo "<th>Less 5%</th>"; echo "<th>Less 10%</th>"; echo "<th>Less 15%</th>"; echo "<th>Less 20%</th>"; echo "<th>Less 25%</th>"; echo "<th>Less 30%</th>"; echo "<th>Less 35%</th>"; echo "<th>Less 40%</th>"; echo "<th>Less 45%</th>"; echo "<th>Less 50%</th>"; echo "<th>Less 55%</th>"; echo "<th>Less 60%</th>"; echo "<th>Less 65%</th>"; echo "<th>Less 70%</th>"; echo "<th>Less 75%</th>"; echo "<th>Less 80%</th>"; echo "<th>Less 85%</th>"; echo "<th>Less 90%</th>"; echo "<th>Less 95%</th></tr>"; for ( $counter = 100; $counter <= 1000; $counter += 50) { echo "<tr><td>"; echo $counter; echo "</td><td>"; echo $original_price * $counter; echo "</td></tr>"; } echo "</table>"; ?> I know the multiplication isn't the correct math function but I can't figure out how to get the 5% to generate. I might be way off. Thanks for any suggestions!!!
  25. You just don't know how thankful I am that you took the time to help with this. I was at my wit's end. After you explained about the variables and how I had done the echo, it was so much clearer. I wasn't thinking it through, I suppose. Glad to hear I was at least close to getting it. I just needed a little push. Thanks again!! It worked like a charm!!
×
×
  • 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.