View Full Version : Pennies...
shwaza
02-24-2005, 01:44 AM
Ok, i'm sure most of you have seen this before, either from a teacher, or anywhere else, but it's that old question, where you could either get 250,000 dollars every day for a month, or you could get one penny on the first day, 2 pennies on the second day, 4 pennies on the third day, 8 pennies on the fourth day... etc.
Well, i had to do this for school today, for some odd reason, and i was really bored, so i decided to code up a little php program that would calculate each day, and the total :)
All you do, is type in how many pennys you recieve on the first day, and then it will do the rest :)
Check it out: http://kingdomsofbattle.com/random/penny.php
RexyRex
02-24-2005, 01:46 AM
Sounds like fun. :)
Turn it into a game? :P
Lol, day 120: 8.3076749736556E+34
Now that would be alot of pennies B) I thought about this tooooo long when i read the post and I came up with the following.
1) Just where would I put these pennies?
2) That would be alot of money spent on those penny wrapper things
3) How would I get them to the bank?
4) What bank would even take that many?
5) just imagin the wait as the bank Teller counted it for deposit
i stopped there cause my brain hurt
Blessings,David
Ill just take the 250,000 a day thanks :lol:
RexyRex
02-24-2005, 04:52 AM
I was thinking...
Did you use an if-else statement? That'd save time..
shwaza
02-24-2005, 11:07 AM
Here, i'll show you the source if you want
<form action="penny.php" method="post">
How many pennies will you get on the first day?<br>
<input type="text" name="penny">
<input type="submit" name="submit" value="Get The Days!">
</form>
<?php
if($_POST['penny'])
{
$day1=$_POST['penny'];
$day2=$day1 * 2;
$day3=$day2 * 2;
$day4=$day3 * 2;
$day5=$day4 * 2;
$day6=$day5 * 2;
$day7=$day6 * 2;
$day8=$day7 * 2;
$day9=$day8 * 2;
$day10=$day9 * 2;
$day11=$day10 * 2;
$day12=$day11 * 2;
$day13=$day12 * 2;
$day14=$day13 * 2;
$day15=$day14 * 2;
$day16=$day15 * 2;
$day17=$day16 * 2;
$day18=$day17 * 2;
$day19=$day18 * 2;
$day20=$day19 * 2;
$day21=$day20 * 2;
$day22=$day21 * 2;
$day23=$day22 * 2;
$day24=$day23 * 2;
$day25=$day24 * 2;
$day26=$day25 * 2;
$day27=$day26 * 2;
$day28=$day27 * 2;
$day29=$day28 * 2;
$day30=$day29 * 2;
echo "Day 1: ". $day1. "<br>";
echo "Day 2: ". $day2. "<br>";
echo "Day 3: ". $day3. "<br>";
echo "Day 4: ". $day4. "<br>";
echo "Day 5: ". $day5. "<br>";
echo "Day 6: ". $day6. "<br>";
echo "Day 7: ". $day7. "<br>";
echo "Day 8: ". $day8. "<br>";
echo "Day 9: ". $day9. "<br>";
echo "Day 10: ". $day10. "<br>";
echo "Day 11: ". $day11. "<br>";
echo "Day 12: ". $day12. "<br>";
echo "Day 13: ". $day13. "<br>";
echo "Day 14: ". $day14. "<br>";
echo "Day 15: ". $day15. "<br>";
echo "Day 16: ". $day16. "<br>";
echo "Day 17: ". $day17. "<br>";
echo "Day 18: ". $day18. "<br>";
echo "Day 19: ". $day19. "<br>";
echo "Day 20: ". $day20. "<br>";
echo "Day 21: ". $day21. "<br>";
echo "Day 22: ". $day22. "<br>";
echo "Day 23: ". $day23. "<br>";
echo "Day 24: ". $day24. "<br>";
echo "Day 25: ". $day25. "<br>";
echo "Day 26: ". $day26. "<br>";
echo "Day 27: ". $day27. "<br>";
echo "Day 28: ". $day28. "<br>";
echo "Day 29: ". $day29. "<br>";
echo "Day 30: ". $day30. "<br>";
$total=$day1 + $day2 + $day3 + $day4 + $day5 + $day6 + $day7 + $day8 + $day9 + $day10 + $day11 + $day12 + $day13 + $day14 + $day15 + $day16 + $day17 + $day18 + $day19 + $day20 + $day21 + $day22 + $day23 + $day24 + $day25 + $day26 + $day27 + $day28 + $day29 + $day30;
echo "<p>Total (in pennies): ". $total. "</p>";
}
?>
Lol, yeah it's long, but i like having each variable on one line, because it's easier to read.
undacuvabruva
02-24-2005, 01:12 PM
wow...
I just had a question..
do your pennies stop after the month?
or do they keep on rollin, and rollin, for the rest of your life?
How cool would it be to have a HUGE pile of pennies in your room.
Or to have like, a penny room in your house, where you keep all your pennies.
Hose them down and go swimming in pennies
shwaza
02-24-2005, 08:45 PM
Lol, no, it's just for one month :P And they'd probably start giving you bills after a few days :P
Heh, I remember we were asked this in 4th Grade, and we all wanted the $250,000 each day.. Then we saw that the pennies were worth more :)
Anyway, since I'm the meanie that I am, I shortened your script to about 22 lines to make it simpler:
<form action="?" method="post">
How many pennies will you get on the first day?<br>
<input type="text" name="penny">
<input type="submit" name="submit" value="Get The Days!">
</form>
<?php
if ($_POST['penny'])
{
$perday = $_POST['penny'];
$lastnum = $_POST['penny']/2;
$Total = 0;
for($i=1; $i<=30; $i++)
{
$PenniesToday = $lastnum * 2;
$lastnum = $PenniesToday;
$Total += $PenniesToday;
echo "Day $i: " . $PenniesToday . "<br />";
}
echo "<p>Total(in pennies): " . $Total . "</p>";
echo "<p>Total(in dollars): $" . $Total/100 . "</p>";
}
?>
Tim
Edit: That didn't work as good as I expected :) I'll try again..
Edit 2: There we go, all working :)
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.