Jump to content

[SOLVED] Tower equalling 100%


MasterACE14

Recommended Posts

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

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.

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).

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)?

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.