redarrow Posted October 9, 2009 Share Posted October 9, 2009 Advance thank you. I was creating a advance basket for a company and i am stuck. not used the old maths function's for years can you help.. looks wrong. <?php $price="20.00"; $quienty="4"; $shipping="7.50"; $discount="20%"; $tax="17.50"; $payments="12"; $total=$price*$quienty; $total=$total+$shipping; $total=$total-$discount; $taxrate=$tax/100; $taxrate=$taxrate+1; $total=$total*$taxrate; $monthly=$total/$payments; echo "Complete total ".£.number_format($total,2)."\n <br> $payments monthly payments ".£.number_format($monthly,2)." "; ?> result Complete total £79.31 // how this correct no way? 12 monthly payments £6.61 // looks ok? from above result. Quote Link to comment Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 What are you needing help with exactly? I don't understand where your difficulties are at. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 9, 2009 Author Share Posted October 9, 2009 read and test it, your see it wrong result, see for your self? posted example below? please dont change the format i have wrote the code just correct my silly ness Quote Link to comment Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 Once thing I noticed $total = $total - $discount $discount is 20%. Can you subtract a real with a percent? Also, that would total to about 87.5 without taxes. Whats so wrong about the numbers? Whats it supposed to be? Also, everything looks fine to me besides the percent subtracting from a real. EDIT: I just calculated myself and came to about 80 pounds. I don't think your code is wrong. Thats just the price. 17.5% is a hefty tax. 20 * 4 = (Price without anything) 80 * .8 ( .8 = 4/5 = 80% of orignal) 64 * 1.175 = 75.2 (Taxes) 75.2 + 7.50 = 81.2 (Shipping, shipping doesn't have sales tax) Edit: Yeah I screwed up my statistics and modified them to be accurate. 80$ is price, then discount, then you add the taxes, then shipping price. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 9, 2009 Author Share Posted October 9, 2009 London is hefty lol, not my fault, not prime minister pal, lol... can you show me the same in a OOP code please i love learning that stuff.... whale i thort ill ask on here because i am no good at php and i got it correct first time no way? Quote Link to comment Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 What is the number you are wanting it to be? Through how sales go, I think it would be 81.2, but frankly you aren't saying the number you want so I don't know if I have what you are gunning for or not. I don't know OOP so can't help you there. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 9, 2009 Author Share Posted October 9, 2009 PugJr <<<<<<<<<< made my day good person nice to no... SOLVED Quote Link to comment Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 Glad I could help...Even though I didn't do anything. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 9, 2009 Author Share Posted October 9, 2009 Here a function way, nice i think ? <?php function add_shopping($price,$quienty,$shipping,$discount,$tax,$payments){ $total=$price*$quienty; $total=$total+$shipping; $total=$total-$discount; $taxrate=$tax/100; $taxrate=$taxrate+1; $total=$total*$taxrate; $monthly=$total/$payments; echo "Complete total ".£.number_format($total,2)."\n <br> $payments monthly payments ".£.number_format($monthly,2)." "; return; } echo add_shopping('20.00','10','7.50','10%','17.50','12'); ?> short version <?php function add_shopping($price,$quienty,$shipping,$discount,$tax,$payments){ $total=($price*$quienty)+($shipping)-($discount); $taxrate=($tax/100)+($taxrate+1); $total=$total*$taxrate; $monthly=$total/$payments; echo "Complete total ".£.number_format($total,2)."\n <br> $payments monthly payments ".£.number_format($monthly,2)." "; return; } echo add_shopping('20.00','1','7.50','10%','17.50','12'); ?> shortest i personally can go. <?php function add_shopping($price,$quienty,$shipping,$discount,$tax,$payments){ $total=($price*$quienty)+($shipping)-($discount); $taxrate=($tax/100)+1; $total=$total*$taxrate; $monthly=$total/$payments; echo "Complete total ".£.number_format($total,2)."\n <br> $payments monthly payments ".£.number_format($monthly,2)." "; return; } echo add_shopping('20.00','1','7.50','10%','17.50','12'); ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 9, 2009 Author Share Posted October 9, 2009 Last post on this sorry. I added session's so the design of the web page, can be set up correctly. <?php session_start(); function add_shopping($price,$quienty,$shipping,$discount,$tax,$payments){ $total=($price*$quienty)+($shipping)-($discount); $taxrate=($tax/100)+1; $total=$total*$taxrate; $monthly=$total/$payments; $_SESSION['monthly']=$monthly; $_SESSION['total']=$total; $_SESSION['payments']=$payments; return; } echo add_shopping('20.00','1','7.50','10%','17.50','12'); echo "Complete total ".£.number_format($_SESSION['total'],2)."\n <br> {$_SESSION['payments']} monthly payments ".£.number_format($_SESSION['monthly'],2)." "; ?> If you learn all this maths stuff, as i have posted you can design a grate cart script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.