Newbie Question???
Author Message
Newbie Question???

I was wondering if any of u nice proggy people could help me???

I wrote the program below as part of an course exercise and it works,
however I was wondering how I would go about making the program give the
user the option to restart or end the program???

program exercise;
{Program written by Turlach Morgan}
{This program will calculate the number of each denomination of coin
used to make a payment of up to 99 pence.}
uses crt;

var
payment :  integer;
fifty,twenty,ten,five,two,one : integer;
bell : char;

begin
writeln;
writeln;
writeln('      This program will work out the least');
writeln('         possible number of each coin');
writeln('           used to make any payment');
writeln('               up to 99 pence.');
writeln;
write('           press <RETURN> to continue');
clrscr;

writeln;
write('              enter payment : ');
writeln;
writeln;

if payment > 99 then
begin
bell := ^G;
writeln('                   WARNING');
writeln('                  ---------');
writeln('!!!!The payment you entered exceeds the maximum.!!!!');
writeln('    --------------------------------------------');
writeln('          This program has terminated.',bell);
end
else
begin
writeln;

writeln('             Press ENTER for result ');
write ('             ======================');
while not keypressed do;

fifty := payment div 50;
if fifty >= 1 then
begin
writeln;
writeln;
writeln ('                 50 pences = ',fifty);
end
else
;
twenty := (payment mod 50) div 20;
if twenty >= 1 then
begin
writeln ( '                 20 pences = ',twenty);
end
else
;
payment := payment mod 50;
ten := (payment mod 20) div 10;
if ten >= 1 then
begin
writeln ( '                 10 pences = ',ten);
end
else
;
payment := payment mod 20;
five := (payment mod 10) div 5;
if five >= 1 then
begin
writeln ( '                  5 pences = ',five);
end
else
;
payment := payment mod 10;
two := (payment mod 5) div 2;
if two >= 1 then
begin
writeln ('                  2 pences = ',two);
end
else
;
payment := payment mod 5;
one := (payment mod 2) div 1;
if one >= 1 then
begin
writeln ( '                  1 pences = ',one);
end
else
; end

end.

Tue, 15 Apr 2003 17:13:07 GMT
Newbie Question???

Quote:

> I was wondering if any of u nice proggy people could help me???

> I wrote the program below as part of an course exercise and it works,
> however I was wondering how I would go about making the program give the
> user the option to restart or end the program???

In general you construct a loop like this:

var
done: Boolean;

begin {main program}
done := false;
repeat
{do stuff}
{ask user if they want to quit, make "done" true if so}
until done
end.

--
______________________________________________________________________
The Scarlet Manuka,      |        Nitpickers' Party motto:
Pratchett Quoter At Large,  |  "He who guards his lips guards his
First Prophet of Bonni, is:  |  soul, but he who speaks rashly will

______________________________|_______________________________________

Tue, 15 Apr 2003 17:28:12 GMT
Newbie Question???

Quote:

> > I was wondering if any of u nice proggy people could help me???

> > I wrote the program below as part of an course exercise and it works,
> > however I was wondering how I would go about making the program give the
> > user the option to restart or end the program???

> In general you construct a loop like this:

> var
>   done: Boolean;

> begin {main program}
>   done := false;
>   repeat
>     {do stuff}
>     {ask user if they want to quit, make "done" true if so}
>   until done
> end.

Or you can use a function, such as

REPEAT
dosomecalculation
UNTIL timetoquit

where "timetoquit" is a boolean function that you write that asks the "Time to
quit?" question, gets the answer, and returns true or false as appropriate.

Bob Schor
Pascal Enthusiast

Fri, 18 Apr 2003 04:17:12 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages