Graxeon Posted January 18, 2010 Share Posted January 18, 2010 I'm trying to echo how many times it takes to get rid of an item (the equation is in the if statement): <?php $cash = $_GET['cash']; $cost = $_GET['cost']; $profit = $_GET['profit']; $times = $_GET['times']; $equation = 0; for ($i=0;$i<$times;$i++) { $cash+= ($cash / $cost * $profit); } $originalcash = $_GET['cash']; $profitnew = $cash - $originalcash; $buystarting = $originalcash / $cost; $buyending = $cash / $cost; echo "Starting Cash: " . number_format($originalcash,2,'.',','); echo "<br />Ending Cash: " . number_format($cash,2,'.',','); echo "<br />Total Profit: <b>" . number_format($profitnew,2,'.',',') . "</b>"; echo "<br />"; echo "<br />Cost per item: " . number_format($cost,2,'.',','); echo "<br />Profit per item: " . number_format($profit,2,'.',','); echo "<br />Times: " . number_format($times,2,'.',','); echo "<br />Total items you can buy with Starting Cash: " . number_format($buystarting,2,'.',','); echo "<br />Total items you can buy with Ending Cash: " . number_format($buyending,2,'.',','); echo "<br /><br />"; $unlock = $_GET['unlock']; if($unlock=="yes") { $shards = $_GET['shards']; $shardsstarting = $shards * $buystarting; $shardsending = $shards * $buyending; $trades = $shardsstarting / 50000; $trades2 = $shardsending / 50000; echo "<br />Total Shards made with Starting Cash: " . number_format($shardsstarting,2,'.',','); echo "<br />Total trades at start: " . number_format($trades,2,'.',','); echo "<br />Total Shards made with Ending Cash: " . number_format($shardsending,2,'.',','); echo "<br />Total trades at end: " . number_format($trades2,2,'.',','); $originalcash2 = $_GET['cash']; $equation2 = 0; for ($i=0;$i<$times;$i++) { $originalcash2+= ($originalcash2 / $cost * $shards / 50000); } echo "<br />Total Trades: " . number_format($originalcash2,2,'.',','); exit; } ?> It's outputting the correct amount of times it takes to get rid of the "shards" but it's also adding "$originalcash" to it. If I try subtracting "$originalcash" then it gives me a totally different number (not what you'd expect). How can I fix it to just show how many times it takes to get rid of "$equation2"? So say the we had this: equation.php?cash=100&cost=20&profit=4×=7&shards=59&unlock=yes To find out how many times it takes to get rid of $equation2 this would happen: 100/20 = 5 5*59 = 295 (first set of shards out of "×=3") (start 2nd "×=3") 120/20 = 6 (120 is $cash + $cash/$cost * $profit) 6*59 = 354 (second set of shards out 3) (start 3rd "×=3") 144/20 = 7.2 7.2*59 = 424.8 (now add up all of the values) 295+354+424.8 = 1073.8 (now divive by 50,000) 1073.8/50000 = 0.021476 (50,000 is just a number I picked) Quote Link to comment https://forums.phpfreaks.com/topic/188926-equation-problem/ Share on other sites More sharing options...
Graxeon Posted January 18, 2010 Author Share Posted January 18, 2010 Let me shorten the post a little Here's my equation: $originalcash2 = $_GET['cash']; $equation2 = 0; for ($i=0;$i<$times;$i++) { $originalcash2+= ($originalcash2 / $cost * $shards / 50000); } echo "<br />Total Trades: " . number_format($originalcash2,2,'.',','); exit; } I call that script by saying: equation.php?cash=100&cost=20&profit=4×=7&shards=59&unlock=yes And I need the equation to do this: 100/20 = 5 5*59 = 295 (first set of shards out of "×=3") (start 2nd "×=3") 120/20 = 6 (120 is $cash + $cash/$cost * $profit) 6*59 = 354 (second set of shards out 3) (start 3rd "×=3") 144/20 = 7.2 7.2*59 = 424.8 (now add up all of the values) 295+354+424.8 = 1073.8 (now divive by 50,000) 1073.8/50000 = 0.021476 (50,000 is just a number I picked) Quote Link to comment https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-997683 Share on other sites More sharing options...
Graxeon Posted January 19, 2010 Author Share Posted January 19, 2010 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-997817 Share on other sites More sharing options...
oni-kun Posted January 19, 2010 Share Posted January 19, 2010 Any ideas? Can you implement your calculation in a loop? You could fairly easily iterate a count for each time the number is modified, store it into an array and count it (or simply +1 to a number). $originalcash2 = $_GET['cash']; $equation2 = 0; $c = 0; for ($i=0;$i<$times;$i++) { $originalcash2+= ($originalcash2 / $cost * $shards / 50000); $c++; } echo "<br />Total Trades: " . number_format($originalcash2,2,'.',','); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-997819 Share on other sites More sharing options...
Graxeon Posted January 19, 2010 Author Share Posted January 19, 2010 It gives the same result. Here's the test page: http://t3st1ng.ulmb.com/equation.php?cash=14000000&cost=1532&profit=18×=1&shards=59&unlock=yes Quote Link to comment https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-998018 Share on other sites More sharing options...
ChemicalBliss Posted January 19, 2010 Share Posted January 19, 2010 uh, i may be missing the point entirely but.. You mean this? Change "+=" to "=" on line 48 -CB- Quote Link to comment https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-998056 Share on other sites More sharing options...
Graxeon Posted January 19, 2010 Author Share Posted January 19, 2010 uh, i may be missing the point entirely but.. You mean this? Change "+=" to "=" on line 48 -CB- That works but only if "times=1". If it's anything higher than 1 then it just displays 0. Same test page: http://t3st1ng.ulmb.com/equation.php?cash=14000000&cost=1532&profit=18×=2&shards=59&unlock=yes Quote Link to comment https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-998167 Share on other sites More sharing options...
ChemicalBliss Posted January 19, 2010 Share Posted January 19, 2010 You have it in there but your not using it for some reason: $equation2 . use $equation2 += .... instead of $originalcash2 += ... then just change the variable in the number_format function. -CB- Quote Link to comment https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-998187 Share on other sites More sharing options...
Graxeon Posted January 19, 2010 Author Share Posted January 19, 2010 Perfect! Thank you Quote Link to comment https://forums.phpfreaks.com/topic/188926-equation-problem/#findComment-998213 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.