PHP :: Aufgabe #32

2 Lösungen Lösungen öffentlich

99 Bottles of Beer - Selbstständige Lösung

Anfänger - PHP von pocki - 11.01.2013 um 14:07 Uhr
Programmiere eine eigenständige Lösung zur gängigen Programmier-Übung bzw. Lied 99 Bottles of Beer

Ausgabe:

Konsolenausgabe:


99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 99 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
... usw.

Lösungen:

vote_ok
von bibir (1870 Punkte) - 08.09.2014 um 15:13 Uhr
Quellcode ausblenden PHP-Code
$i = 99;
while($i > 0){
	echo '<p>'.$i.' bottles of beer on the wall, '
		.$i.' bottles of beer.<br />
		Take one down and pass it around, '
		.($i-1).' bottles of beer on the wall.</p>';
	$i--;
}
vote_ok
von paddlboot (2970 Punkte) - 08.08.2019 um 12:48 Uhr
Quellcode ausblenden PHP-Code
<?php

for($bottles = 99; $bottles > 0; $bottles--)
{
	if($bottles == 2)
	{
		echo $bottles.' bottles of beer on the wall, '.$bottles.' of beer.<br/>';
		echo 'Take one down and pass it around, one bottle of beer on the wall.<br/><br/>';
	}
	else if($bottles == 1)
	{
		echo 'One bottle of beer on the wall, one bottle of beer.<br/>';
		echo 'Take it down and pass it around, no bottle of beer on the wall.<br/><br/>';
	}
	else
	{
		echo $bottles.' bottles of beer on the wall, '.$bottles.' bottles of beer.<br/>';
		echo 'Take one down and pass it around, '.($bottles-1).' bottles of beer on the wall.<br/><br/>';
	}	
}


?>