Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Pascal

Date:02/28/06
Author:Michael Niedermayr
URL:http://www.niedermayr.cc
Comments:8
Info:n/a
Score: (3.01 in 92 votes)
program BottlesOfBeer (output);
{this program plays the 99 bottles of beer song}

const
  BOTTLESSTART = 99;
  BOTTLESEND = 1;

type
  tBottles = BOTTLESEND..BOTTLESSTART;

var
  bottles : tBottles;

begin
  for bottles := BOTTLESSTART downto BOTTLESEND do
  begin
    if bottles > 1 then
    begin
      writeln (bottles,' bottles of beer on the wall, ',bottles, ' bottles of beer.');
      write ('Take one down, pass it around, ');
      writeln (bottles - 1, ' bottles of beer on the wall.');
      writeln
    end
    else
    begin
      writeln ('1 bottle of beer on the wall, one bottle of beer.');
      writeln ('Take one down, pass it around, no more bottles of beer on the wall');
      writeln;
      writeln ('No more bottles of beer on the wall, no more bottles of beer.');
      writeln ('Go to the store and buy some more, 99 bottles of beer on the wall.')    
    end
  end
end.

Download Source | Write Comment

Alternative Versions

Comments

>>  rurilu said on 11/23/06 17:40:50

rurilu program BottlesOfBeer (output);
{this program plays the 99 bottles of beer song}

type
tBottles = 1..99;
var
bottles : tBottles;


begin
for bottles := 99 downto 2 do
begin
writeln (bottles,' bottles of beer on the wall, ',bottles, ' bottles of beer.');
write ('Take one down, pass it around, ');
writeln (bottles - 1, ' bottles of beer on the wall.');
writeln
end
writeln ('1 bottle of beer on the wall, one bottle of beer.');
writeln ('Take one down, pass it around, no more bottles of beer on the wall');
writeln;
writeln ('No more bottles of beer on the wall, no more bottles of beer.');
writeln ('Go to the store and buy some more, 99 bottles of beer on the wall.')
end.

>>  Catox said on 11/29/06 22:02:40

Catox Program BottleOfBeer;
{ just for fun, an Object oriented Bottle Of Beer }
{ with special attention to typos }

Type Bottle = object
Q : byte;
procedure Buy(n : byte);
function Count : String;
procedure Sing;
procedure Drink;
end;

Var B : Bottle;

Procedure Bottle.Buy(n : byte);
Begin
Q:=n;
writeln('Go to the store and buy some more, '+Count+' on the wall.');
End;

Function Bottle.Count : String;
var s : string;
Begin
str(Q,s);
case q of
0 : s:='no more bottles';
1 : s:='1 bottle';
else
s:=s+' bottles';
end;
Count:=s+' of beer';
End;

Procedure Bottle.Sing;
var s1, s2 : string;
Begin
s1:=Count;
s2:=Count;
s1[1]:=upcase(s1[1]);
Writeln(s1+' on the wall, '+s2+'.');
End;

Procedure Bottle.Drink;
Begin
dec(Q);
Writeln('Take one down and pass it arround, '+Count+' on the wall.');
End;


BEGIN
B.Q:=99;
repeat
B.Sing;
B.Drink;
Writeln;
until B.Q=0;
B.Sing;
B.Buy(99);
readln;
END.

>>  Eltaryn said on 08/09/07 03:35:59

Eltaryn program BottlesOfBeer;

Label label1;

var
bottles: integer;

begin
writeln('please enter the number of bottles starting on the wall');
(*max of 148 *)
readln(bottles);

Label1:

writeln (bottles,' bottles of beer on the wall, ',bottles, ' bottles of beer.');
write ('Take one down, pass it around, ');
bottles:= bottles -1;
writeln (bottles, ' bottles of beer on the wall.');
If bottles <> 1 then goto label1;

begin
writeln ('1 bottle of beer on the wall, one bottle of beer.');
writeln ('Take one down, pass it around, no more bottles of beer on the wall');
writeln;
writeln ('No more bottles of beer on the wall, no more bottles of beer.');
writeln ('Go to the store and buy some more, 99 bottles of beer on the wall.')
end;
readln;
end.

>>  Flam0r said on 11/23/07 15:56:24

Flam0r Compared to them awesome JAVA, Perl and Visual Basic Versions of this programm this - and I am sorry to say this - is a piece of shit!!!
a baby could programm this!

>>  N. Kraft said on 03/14/08 15:17:36

N. Kraft Some of you folks are just trying too hard...this isn't Delphi, after all:

Program Bottles;

Var i : Integer;

Begin
i := 99;
Repeat
Writeln(i, ' bottles of beer on the wall, ', i, ' bottles of beer');
Writeln('Take one down and pass it around');
i := i-1;
Writeln(i, ' bottles of beer on the wall.');
Until i = 0;
Writeln('No more bottles of beer on the wall, no more bottles of beer');
Writeln('Go to the store and buy some more, 99 bottles of beer on the wall');
End.


>>  MOSFET said on 04/20/08 15:52:06

MOSFET Pascal rocks. But you can't do much with it these days... Great first-language, though.

>>  djwds said on 10/20/09 22:03:41

djwds program bottles ;
var i:byte;
begin
for i:=1 to 98 do
begin
writeln ( 100-i, ' bottles of bear on the wall ' ,100-i, ' bottles of bear');
write(' Take one down, pass it around ');
writeln(99-i, ' bottles of bear on the wall');
readln;
end;
begin
writeln ('1 bottle of beer on the wall, one bottle of beer.');
writeln ('Take one down, pass it around, no more bottles of beer on the wall');
writeln;
writeln ('No more bottles of beer on the wall, no more bottles of beer.');
writeln ('Go to the store and buy some more, 99 bottles of beer on the wall.')
readln;
end;
end.



It was very easy

>>  MiSchi said on 08/13/10 11:40:47

MiSchi program BottlesOfBeer (output);
{this program plays the 99 bottles of beer song}
{takes particular care of singular for only one bottle.}

var
bottles: 2..98;

begin
writeln ('99 bottles of beer on the wall, 99 bottles of beer.');
for bottles := 98 downto 2 do
begin
writeln ('Take one down, pass it around, ', bottles, ' bottles of beer on the wall.');
writeln;
writeln (bottles,' bottles of beer on the wall, ', bottles, ' bottles of beer.');
end;
writeln ('Take one down, pass it around, 1 bottle of beer on the wall.');
writeln;
writeln ('1 bottle of beer on the wall, 1 bottle of beer.');
writeln ('Take one down, pass it around, no more bottles of beer on the wall');
writeln;
writeln ('No more bottles of beer on the wall, no more bottles of beer.');
writeln ('Go to the store and buy some more, 99 bottles of beer on the wall.')
end.

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: