Board index » delphi » Help Required Please

Help Required Please

Quote
----- Original Message -----
From: Paul <sp...@s2new.freeserve.co.uk>
Newsgroups: comp.lang.pascal.borland
Sent: Tuesday, June 27, 2000 8:58 PM
Subject: Assistance required please

> I need to put a loop on the following validation. I have been trying but
> without
> success to date..... about time to pull my hair out, what's left that is!

> Any assistance gratefully received.

> writeln ('Enter Room Number  :');
>   readln (Roomnr);
>     if (Roomnr < 1) or (Roomnr > 12) then
>       begin
>         writeln;
>         writeln ('Room Number Incorrect :');
>       end  {End of statement   }
>     else
>       Continue := 'Y';
>   until Continue = 'Y';

> Regards

> Paul

 

Re:Help Required Please


I think what you want to use is a for loop...  Or while...!
try this:
{Repeat Loop}
repeat
    writeln{'Enter rm #');
    readln(roomnr);
    if (roomnr < 1) or (roomnr > 12) then writeln ('Room Number Incorrect :');
until (roomnr > 1) or (roomnr < 12);
{For Loop}
for i := 1 to 10 do
 begin
    writeln{'Enter rm #');
    readln(roomnr);
    if (roomnr < 1) or (roomnr > 12) then writeln ('Room Number Incorrect :')
    else end;
    inc(i,1);
 end;

I think that should do it...???
Also, try to advoid using capitals and lowercase through out your code, this
will help you out greatly when you move on to C or Java where everything is
case sensitive.
-Mike Gerschefske

Quote
Paul wrote:
> ----- Original Message -----
> From: Paul <sp...@s2new.freeserve.co.uk>
> Newsgroups: comp.lang.pascal.borland
> Sent: Tuesday, June 27, 2000 8:58 PM
> Subject: Assistance required please

> > I need to put a loop on the following validation. I have been trying but
> > without
> > success to date..... about time to pull my hair out, what's left that is!

> > Any assistance gratefully received.

> > writeln ('Enter Room Number  :');
> >   readln (Roomnr);
> >     if (Roomnr < 1) or (Roomnr > 12) then
> >       begin
> >         writeln;
> >         writeln ('Room Number Incorrect :');
> >       end  {End of statement   }
> >     else
> >       Continue := 'Y';
> >   until Continue = 'Y';

> > Regards

> > Paul

Re:Help Required Please


Quote
> I think what you want to use is a for loop...  Or while...!
> try this:
> {Repeat Loop}
> repeat
>     writeln{'Enter rm #');
>     readln(roomnr);
>     if (roomnr < 1) or (roomnr > 12) then writeln ('Room Number Incorrect :');
> until (roomnr > 1) or (roomnr < 12);
> {For Loop}
> for i := 1 to 10 do
>  begin
>     write{'Enter rm # '); readln(roomnr);
>     if (roomnr < 1) or (roomnr > 12) then writeln ('Room Number Incorrect :')
>     else end;
>     inc(i,1);
>  end;

> I think that should do it...???

   No, I disagree.  A For loop is very much the wrong choice for a loop
(which doesn't have a finite number of iterations stated/planned).  A
While loop would work, but I feel the Repeat loop is best here.
   Now, your Repeat loop isn't correct - for his problem.  Your loop will
exit (terminate) with value in the range 2..11, which isn't how the
problem is presented.  The loop should terminate when any value 1-12 is
entered.  Also, using a compound termination condition isn't required,
and the more that's added, the greater chance there is for a coding or
logic error (I think it happened to you...).
   So, I would do it otherwise, and one simple way is:
        until RoomNr in [1..12]
which states clearly what the termination condition is...as well as
verifies the problem's logic, I feel.
   Lastly, (added) code to handle pathological data entry (non-numerics)
would be good, too: it would be unfortunate for such a simple program to
abort just because some idiot didn't key in numerics digits, wouldn't you
agree?  8<}}

Quote
> Also, try to advoid using capitals and lowercase through out your code, this
> will help you out greatly when you move on to C or Java where everything is
> case sensitive.

   C'mon...that isn't really necessary.  Does it follow that _every_
Pascal programmer will "move to C/C++ or Java"?  I hardly think it's
necessary to impose the harsh restrictions of another language on someone
who's clearly learning to acquire the basics of programming...and there
are a great many people in the world who _don't_ use a case-sensitive
programming language!

Re:Help Required Please


According to the problem it wants a value greater then one, and a value less then
12, not a value greater then or equal to one, nor a value less then or equal to 12.
Also, no, I didn't bother even testing my code down there (Yes, I know, shame on
me).  Just as well, I do think the majority of people that learn pascal go on to
learn C/C++ and so on.  Besides, mixing cases is bad form anyways (ie Roomnr,
roomnr).  Also, no worries here, his question was well answered in
news://news.uswest.net/comp.lang.pascal.borland
-Mike

"Pascal...  From the creators of Pascal's Triangle"

Quote
Mike Copeland wrote:
> > I think what you want to use is a for loop...  Or while...!
> > try this:
> > {Repeat Loop}
> > repeat
> >     writeln{'Enter rm #');
> >     readln(roomnr);
> >     if (roomnr < 1) or (roomnr > 12) then writeln ('Room Number Incorrect :');
> > until (roomnr > 1) or (roomnr < 12);
> > {For Loop}
> > for i := 1 to 10 do
> >  begin
> >     write{'Enter rm # '); readln(roomnr);
> >     if (roomnr < 1) or (roomnr > 12) then writeln ('Room Number Incorrect :')
> >     else end;
> >     inc(i,1);
> >  end;

> > I think that should do it...???

>    No, I disagree.  A For loop is very much the wrong choice for a loop
> (which doesn't have a finite number of iterations stated/planned).  A
> While loop would work, but I feel the Repeat loop is best here.
>    Now, your Repeat loop isn't correct - for his problem.  Your loop will
> exit (terminate) with value in the range 2..11, which isn't how the
> problem is presented.  The loop should terminate when any value 1-12 is
> entered.  Also, using a compound termination condition isn't required,
> and the more that's added, the greater chance there is for a coding or
> logic error (I think it happened to you...).
>    So, I would do it otherwise, and one simple way is:
>         until RoomNr in [1..12]
> which states clearly what the termination condition is...as well as
> verifies the problem's logic, I feel.
>    Lastly, (added) code to handle pathological data entry (non-numerics)
> would be good, too: it would be unfortunate for such a simple program to
> abort just because some idiot didn't key in numerics digits, wouldn't you
> agree?  8<}}

> > Also, try to advoid using capitals and lowercase through out your code, this
> > will help you out greatly when you move on to C or Java where everything is
> > case sensitive.

>    C'mon...that isn't really necessary.  Does it follow that _every_
> Pascal programmer will "move to C/C++ or Java"?  I hardly think it's
> necessary to impose the harsh restrictions of another language on someone
> who's clearly learning to acquire the basics of programming...and there
> are a great many people in the world who _don't_ use a case-sensitive
> programming language!

Re:Help Required Please


Hi,

Quote
Mike Copeland wrote:
>> Also, try to advoid using capitals and lowercase through out your code, this
>> will help you out greatly when you move on to C or Java where everything is
>> case sensitive.

>    C'mon...that isn't really necessary.  Does it follow that _every_
> Pascal programmer will "move to C/C++ or Java"?

And the case sensitivity of identifier names is certainly one the most
stupid features of these languages. Considering the C look-alike
contest currently being held among language designers, however, I
don't expect it to vanish from the face of the planet anytime soon...

 - Sebastian

Re:Help Required Please


Many thanks for all the replies, helped me sort the thing out.
Assignment now handed in...... awaiting result.

Thanks again to all that replied.

Paul.

Quote
Paul <sp...@s2new.freeserve.co.uk> wrote in message

news:8jb23f$slh$1@news6.svr.pol.co.uk...
Quote
> ----- Original Message -----
> From: Paul <sp...@s2new.freeserve.co.uk>
> Newsgroups: comp.lang.pascal.borland
> Sent: Tuesday, June 27, 2000 8:58 PM
> Subject: Assistance required please

> > I need to put a loop on the following validation. I have been trying but
> > without
> > success to date..... about time to pull my hair out, what's left that
is!

> > Any assistance gratefully received.

> > writeln ('Enter Room Number  :');
> >   readln (Roomnr);
> >     if (Roomnr < 1) or (Roomnr > 12) then
> >       begin
> >         writeln;
> >         writeln ('Room Number Incorrect :');
> >       end  {End of statement   }
> >     else
> >       Continue := 'Y';
> >   until Continue = 'Y';

> > Regards

> > Paul

Other Threads