Board index » delphi » Beginner requires help!

Beginner requires help!

I would appreciate any help anyone can give me as to why this piece of code
{which is actually a procedure in the program testdiv2} won't run properly.
 In case my method of writing code is confusing to anyone - all I am trying
to do is at the end of the program I ask if they would like to divide some
more pairs.  If yes they go to start and continue on from there else
clrscr.  Obviously some of the lines are not quite complete as I copied
them out of DOS and they could not be seen.

Program TestDiv (input,output);

Uses

crt, dos;

Var
{Numerator = Num
Denominator = Denom
Quotient = Quot
Remainder = Remain
Pairs = Prs
Count = Count
Polarity = Pol
Temp = Temp}
Num, Denom, Remain, Prs, Count, Quot, Pol, Temp: Real;
y : string;
          n : string;
          answer : char;

procedure start;

var
          x :integer;
          y :integer;
          line :integer;

begin

          clrscr;
          textcolor (15);
          textbackground (1);
          clrscr;
          y :=1;
          repeat
               begin
                    x := 1;
                    y := y + 1;
                    gotoxy (x,y);
                    textcolor (4);
                    write ('_');
                    x := 80;
                    gotoxy (x,y);
                    writeln ('_');

               end
          until  y = 5;

          x := 0;

          repeat
               begin
                    y := 1;
                    x := x + 1;
                    gotoxy (x,y);
                    write ('_');
               end
          until x = 80;

          X := 0;

          repeat
               begin
                    y := 5;
                    x := x + 1;
                    gotoxy (x,y);
                    write ('_');
               end
          until x = 80;

          gotoxy (2,2);
          textcolor (1);
          textbackground (2);
          write ('  Harry Programming Classes                              
    );
          gotoxy (2,3);
          write ('                                                        
                               );
          gotoxy (2,4);
          writeln ('                     TEST DIVISION PROGRAMME          
   );
          textbackground (1);

end;

begin

          write (' Do you wish to process more Pairs y/n ');
          readln (answer);
          window (1,1,80,25);
               if answer = y then
                    begin

                         clrscr;
                         start;
                    end
               else

         clrscr;
end.

Any help would be greatly appreciated.

Pse post here or e-mail j.har...@netaccess.co.nz

Many thanks.

Harry

 

Re:Beginner requires help!


In article <01bccb92$b4388d00$58ba1...@harrisj.netaccess.co.nz>, John
Harris writes

Quote

>I would appreciate any help anyone can give me as to why this piece of
>code {which is actually a procedure in the program testdiv2} won't run
>properly. > In case my method of writing code is confusing to anyone -
>all I am trying >to do is at the end of the program I ask if they would
>like to divide some more pairs.  If yes they go to start and continue on
>from there else clrscr.  Obviously some of the lines are not quite
>complete as I copied them out of DOS and they could not be seen.

[Code snipped]

Quote
>Any help would be greatly appreciated.

>Pse post here or e-mail j.har...@netaccess.co.nz

>Many thanks.

>Harry

When I read and tried to run your code I found 4 errors. I'll show you
the lines where things went wrong.

The first 3 similar errors are in here:

Quote
>          write ('  Harry Programming Classes                );

                                                             ^ no end
quote
Quote
>          gotoxy (2,3);
>          write ('                                           );

                                                             ^ no end
quote
Quote
>          gotoxy (2,4);
>          writeln ('                     TEST DIVISION PROGRAMME      );

                                                          no end quote^

In the write(ln) statements you forgot the end quotes, so you'll get a
"String constant exceeds line" error when compiling.

The last error isn't difficult, but it's common (at least in my
programming it is :) ).
In you VAR section you declare the variable "answer" as a Char:

Quote
>          answer : char;

but when you try to use "answer" in this line
Quote
>               if answer = y then

you compare "answer" to something that's not a character. Again you
forgot to include the quotes. This is the correct line of code:

                if answer = 'y' then

Mind you, this only checks for a lowercase 'y', so if your user has
CapsLock on and presses the 'y' key, your program still would end.
A better line would be

                if answer = 'y' or answer = 'Y' then

Hope this helps.

Jaap
--
       __ ___    __  __ ______
      / //   |  / / / // ____/          Jaap van Heemst
 __  / // /| | / /_/ // __/        j...@dutlbcz.lr.tudelft.nl
/ /_/ // ___ |/ __  // /___        
\____//_/  |_|_/ /_//_____/    

Re:Beginner requires help!


This is a multi-part message in MIME format.
--------------A797AE5B87BEA6FA624F34B5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Quote
John Harris wrote:
>                if answer = y then
>                     begin
>                          clrscr;
>                          start;
>                     end

First of all you need semi-colons after all of your end statements and then you
need to put single quote around the y in the answer.ex.
answer = 'y' then
    begin
        clrscr;
        start;
    end;

--------------A797AE5B87BEA6FA624F34B5
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for David Owens II
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             David Owens II
n:              Owens II;David
email;internet: david...@sprintmail.com
note:           Life is short, don't waste it!
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
version:        2.1
end:            vcard

--------------A797AE5B87BEA6FA624F34B5--

Re:Beginner requires help!


On 30 Sep 1997 09:26:11 GMT, j...@ANTISPAMdutlbcz.lr.tudelft.nl (Jaap

Quote
van Heemst) wrote:

[clipped]

Quote
>                if answer = 'y' or answer = 'Y' then

Even better is:

if (answer = 'y') or (answer='Y') then

Also, I noticed an

else;

in the original code. This is bad programming as there is an empty
statement after the else. You may simply omit the else and leave the
semi-colon.

Neil Padgett

Re:Beginner requires help!


Even Better;

if UpCase(Answer)='Y' then...

Assuming ANSWER is a CHAR

Re:Beginner requires help!


 Paul Holden wrote in article <343A56B9.6...@psh.compulink.co.uk>...

Quote
>Even Better;

>if UpCase(Answer)='Y' then...

>Assuming ANSWER is a CHAR

If we go do the even better tricks: :)

even better in then netherlands:
if UpCase(Answer) IN ['J',Y'] then ..

cause many will type y to questions asked in dutch

Chris

Re:Beginner requires help!


On Tue, 07 Oct 1997 16:35:21 +0100, Paul Holden

Quote
<p...@psh.compulink.co.uk> wrote:
>Even Better;

>if UpCase(Answer)='Y' then...

>Assuming ANSWER is a CHAR

if UpCase(sAns[1])='Y' will allow you to get your answer in a string
variable, but respond to Yes, Y, y, etc.

Tom

--
http://www.arunet.co.uk/tkboyd/offers.htm
Freeware, shareware for IBM type pcs. Ideas for parents, teachers

Re:Beginner requires help!


"Chris Meijer" <c:z:meijer@wb:utwente:nl> said:

Quote
>If we go do the even better tricks: :)
>even better in then netherlands:
>if UpCase(Answer) IN ['J',Y'] then ..
>cause many will type y to questions asked in dutch

To throw my lot in here, why not save yourself the trouble of using
that variable .. :-p

        if Upcase(readkey)

tihi :)

Re:Beginner requires help!


[Sorry, my software is not inserting attributions properly]
In reply to Jaap van Heemst, Neil Padget wrote:

Quote
>Also, I noticed an

>else;

>in the original code. This is bad programming as there is an empty
>statement after the else. You may simply omit the else and leave the
>semi-colon.

I am only an amateur programmer but it seems to me good practice for the
source code to show that I have considered the possiblity of "else"
action and decided that none is needed.  If the "else" imposes any
overhead on the compiled code, I would be inclined to comment it out

{else} ;

rather than omit it.
--
E. J. J.  (t...@chy-an-piran.demon.co.uk)
For priority attention to e-mail, use "ej ... " address, known to some users.
Regret any inconvenience caused by above - done to downgrade junk mail.

Other Threads