Ruby :: Aufgabe #32
1 Lösung

99 Bottles of Beer - Selbstständige Lösung
Anfänger - Ruby
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:
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:

def bottles99() x = 99 while x >= 1 do if x > 2 then puts "#{x} bottles of beer on the wall,\n#{x} bottles of beer.\nTake one down, pass it around,\n#{x-1} bottles of beer on the wall." elsif x == 2 puts "#{x} bottles of beer on the wall,\n#{x} bottles of beer.\nTake one down, pass it around,\n#{x-1} bottle of beer on the wall." elsif x == 1 puts "One last bottle of beer on the wall,\nOne last bottle of beer.\nTake it down, pass it around,\nNo more bottles of beer on the wall." end x -= 1 end end bottles99()