Language Pascal
| Date: | 02/28/06 |
| Author: | Michael Niedermayr |
| URL: | http://www.niedermayr.cc |
| Comments: | 8 |
| Info: | n/a |
| Score: |
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
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!
Comments
{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.
{ 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.
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.
a baby could programm this!
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.
I'm building my own B2B commercial website (my own business) using PWU tools and Pascal.
I have created embedded products with Pascal and Delphi.
I can not count how many commercial applications I have created or worked on that used Pascal and Delphi.
Truthfully, I find the ease and security of using Pascal a better solution then using PHP, Java, or C++; and speed wise, find it just slightly slower than C with the most recent compilers.
As for a learning language, well, it's great to learn with, and to develop with. It has all the features of the best languages and none of the hiccups in my opinion. (And yes, I have used other languages, 19 of them to date, depending on what was required to get the job done).
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