MasterACE14 Posted October 28, 2008 Share Posted October 28, 2008 I am making a basic tower that equals 100%. But it's not working correctly. I believe the problem is with the percentage variables. $percentage1 is suppose to find the first percentage of 5000, and $percentage2 is suppose to be the percentage of what is left of 5000. here's my code: <?php $percentage1 = (5000) * (3000/100); $percentage2 = (5000) * (2000/100); // part 1 echo "<font color=\"green\">"; for($i = 1; $i < ($percentage1/200); $i++) { echo "||||||||||<br />"; } echo "</font>"; // part 2 echo "<font color=\"blue\">"; for($i = 1; $i < ($percentage2/200); $i++) { echo "||||||||||<br />"; } echo "</font>"; ?> any help is greatly appreciated. Regards ACE Link to comment https://forums.phpfreaks.com/topic/130396-solved-tower-equalling-100/ Share on other sites More sharing options...
bobbinsbro Posted October 28, 2008 Share Posted October 28, 2008 errm... so, you want to make a tower 5000 rows tall where 60% of the rows are green and 40% of the rows are blue? Link to comment https://forums.phpfreaks.com/topic/130396-solved-tower-equalling-100/#findComment-676384 Share on other sites More sharing options...
MasterACE14 Posted October 28, 2008 Author Share Posted October 28, 2008 no lol, but you have the idea. I want the tower to be about 10 rows tall. 60% green and 40% blue. Keeping in mind, the green and blue values will be always changing. so green and blue will always have to equal 100%. can't have for example 60% green and 60% blue, cause the tower expands above 10 rows tall then. That's the problem. Link to comment https://forums.phpfreaks.com/topic/130396-solved-tower-equalling-100/#findComment-676385 Share on other sites More sharing options...
bobbinsbro Posted October 28, 2008 Share Posted October 28, 2008 well, first of all, i don't exactly get what kind of percentages your going for in your code, cause what your doing is setting $percentage1 to be 300% of 5000, and $percentage2 to be 200% of 5000. if you don't want to exceed 10 rows, i think you want to do $i < ($percentage1 % 10) instead of $i < ($percentage1 / 200). or maybe there's a purpose to the /200 in which case you would do $i < (($percentage1 / 200) % 10). Link to comment https://forums.phpfreaks.com/topic/130396-solved-tower-equalling-100/#findComment-676396 Share on other sites More sharing options...
MasterACE14 Posted October 28, 2008 Author Share Posted October 28, 2008 the $percentage / 200 is what im currently using to keep the tower down to the correct amount of rows high. But it really isn't working, and I've tried % 10, I don't know what I'm doing lol Link to comment https://forums.phpfreaks.com/topic/130396-solved-tower-equalling-100/#findComment-676398 Share on other sites More sharing options...
bobbinsbro Posted October 28, 2008 Share Posted October 28, 2008 lol. of course %10 doesn't work. silly me. the $percentage 's are perfectly divisible by 10. lol. tell me, where did the 5000 come from and where do the (3000/100), (2000/100) come from? which of these is the part that constantly changes (to change the blue:green ration)? Link to comment https://forums.phpfreaks.com/topic/130396-solved-tower-equalling-100/#findComment-676408 Share on other sites More sharing options...
MasterACE14 Posted October 28, 2008 Author Share Posted October 28, 2008 the 5000 is the 100% basically. The tower is a meter of how many donations I have received, and the aim is to reach $5,000 and basically, Im breaking the tower into 2 parts. 1 part($percentage1) is for the percent of money received so far out of the 5,000. and the second part, is to build the rest of the tower. for what is left to achieve for the rest of the tower. Link to comment https://forums.phpfreaks.com/topic/130396-solved-tower-equalling-100/#findComment-676462 Share on other sites More sharing options...
bobbinsbro Posted October 28, 2008 Share Posted October 28, 2008 this sort things out: <?php $recieved = 3000; //money recieved so far $toGo = 2000; // amount left to get to goal $goal = 5000; //amount you want $percentage1 = round($recieved/$goal * 10); $percentage2 = round($toGo/$goal * 10); // part 1 echo "<font color=\"green\">"; for($i = 1; $i <= $percentage1; $i++) { echo "||||||||||<br />"; } echo "</font>"; // part 2 echo "<font color=\"blue\">"; for($i = 1; $i <= $percentage2; $i++) { echo "||||||||||<br />"; } echo "</font>"; ?> if you want to change the height of the tower, just multiply by the desired height on line 5,6 instead of multiplying by 10. Link to comment https://forums.phpfreaks.com/topic/130396-solved-tower-equalling-100/#findComment-676479 Share on other sites More sharing options...
MasterACE14 Posted October 28, 2008 Author Share Posted October 28, 2008 that is working perfectly! Thank you so much bobbinsbro! Link to comment https://forums.phpfreaks.com/topic/130396-solved-tower-equalling-100/#findComment-676494 Share on other sites More sharing options...
bobbinsbro Posted October 28, 2008 Share Posted October 28, 2008 your welcome Link to comment https://forums.phpfreaks.com/topic/130396-solved-tower-equalling-100/#findComment-676497 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.