LastFather Posted July 1, 2010 Share Posted July 1, 2010 Hello, On my Stats page on my MMOG text based mafia game, i get a Division by zero error on the My Stats page. I can't work out what it is. Here is the bit of code it relates to (The bottom line - percentage) $currank=$fetch->rank; $rankp = $fetch->rankpoints; if ($currank == "Empty-suit"){ $max = "100"; $old="0"; }elseif ($currank == "Delivery Boy"){ $max = '300'; $old="100"; }elseif ($currank == "Picciotto"){ $max = '800'; $old="300"; }elseif ($currank == "Shoplifter"){ $max = '1500'; $old="800"; }elseif ($currank == "Pickpocket"){ $max = '3500'; $old="1500"; }elseif ($currank == "Thief"){ $max = '6000'; $old="3500"; }elseif ($currank == "Associate"){ $max = '8000'; $old="6000"; }elseif ($currank == "Mobster"){ $max = '12000'; $old="8000"; } elseif ($currank == "Soldier"){ $max = '15000'; $old="12000"; } elseif ($currank == "Swindler"){ $max = '18000'; $old="15000"; } elseif ($currank == "Assassin"){ $max = '22000'; $old="18000"; } elseif ($currank == "Local Chief"){ $max = '28000'; $old="22000"; } elseif ($currank == "Chief"){ $max = '34000'; $old="28000"; } elseif ($currank == "Bruglione"){ $max = '40000'; $old="34000"; } elseif ($currank == "Godfather"){ $max = '200000'; } $percent = round((($rankp-$old)/($max-$old))*100, 2); ?> Link to comment https://forums.phpfreaks.com/topic/206390-division-by-zero-help/ Share on other sites More sharing options...
ejaboneta Posted July 1, 2010 Share Posted July 1, 2010 I've found that a good way to troubleshoot such a problem is by printing the script you are trying to run. what I mean is using this line <?php $percent = round((($rankp-$old)/($max-$old))*100, 2); ?> and printing what its actually doing <?php echo "$percent = round((($rankp-$old)/($max-$old))*100, 2);"; ?> Link to comment https://forums.phpfreaks.com/topic/206390-division-by-zero-help/#findComment-1079736 Share on other sites More sharing options...
Mchl Posted July 1, 2010 Share Posted July 1, 2010 Since there's only one division in entire script, it shouldn't be all that difficilt to fnd out why $max-$old happens to be equal to 0 (probably $currank is not equal to any of the possible choices). BTW: For assignments like this use switch Link to comment https://forums.phpfreaks.com/topic/206390-division-by-zero-help/#findComment-1079791 Share on other sites More sharing options...
LastFather Posted July 1, 2010 Author Share Posted July 1, 2010 I've found that a good way to troubleshoot such a problem is by printing the script you are trying to run. what I mean is using this line <?php $percent = round((($rankp-$old)/($max-$old))*100, 2); ?> and printing what its actually doing <?php echo "$percent = round((($rankp-$old)/($max-$old))*100, 2);"; ?> I got this - = round(((10213-)/(-))*100, 2); Link to comment https://forums.phpfreaks.com/topic/206390-division-by-zero-help/#findComment-1079793 Share on other sites More sharing options...
ejaboneta Posted July 3, 2010 Share Posted July 3, 2010 $currank=$fetch->rank; $rankp = $fetch->rankpoints;[/code] These probably aren't returning any values. Link to comment https://forums.phpfreaks.com/topic/206390-division-by-zero-help/#findComment-1080731 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.