comp.lang.ada
 help / color / mirror / Atom feed
* Please help link list!
@ 1997-12-04  0:00 Eric Sabo
  1997-12-05  0:00 ` Jerry van Dijk
  1997-12-05  0:00 ` bklungle
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Sabo @ 1997-12-04  0:00 UTC (permalink / raw)



This is a multi-part message in MIME format.

------=_NextPart_000_1BB5_01BD004A.9C960820
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

What am I doing wrong with this program?
with gnat.io; use gnat.io;
procedure testing is
type link_integer;
type pointer is access link_integer;
type link_integer is
   record
      number : integer;
      next : pointer;
   end record;
first, last, p : pointer;
temp : integer;
begin
    =20
     put("Project Number two");
     p :=3D new link_integer;
     first :=3D p;
     last :=3D p;
-- Entering the link list
     put_line("Please enter a number: ");
     get(temp);
     while temp /=3D -99 loop
         p.number :=3D temp;
         p :=3D new link_integer;
         last.next :=3D p;
         first.number :=3D temp;
         last :=3D p;
         put_line("Please enter a number: ");
         get(temp);
         first.number :=3D temp;
         first.next :=3D p;
     end loop;     =20
-- printing outing the link list
   temp :=3D first.number;
   while temp /=3D last.number loop
      put("The number is ");
      put(temp);     =20
      temp :=3D p.number;
   end loop;
end testing;

Thanks,
Eric Sabo
sabo@hhs.net

------=_NextPart_000_1BB5_01BD004A.9C960820
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.71.1712.3"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 size=3D2>What am I doing wrong with this=20
program?</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT><FONT size=3D2>with gnat.io; =
use=20
gnat.io;<BR>procedure testing is<BR>type link_integer;<BR>type pointer =
is access=20
link_integer;<BR>type link_integer is<BR>&nbsp;&nbsp;=20
record<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number :=20
integer;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; next : =
pointer;<BR>&nbsp;&nbsp; end=20
record;</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>first, last, p : pointer;<BR>temp :=20
integer;<BR>begin<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
put(&quot;Project Number two&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp; p :=3D =
new=20
link_integer;<BR>&nbsp;&nbsp;&nbsp;&nbsp; first :=3D=20
p;<BR>&nbsp;&nbsp;&nbsp;&nbsp; last :=3D p;<BR>-- Entering the link=20
list<BR>&nbsp;&nbsp;&nbsp;&nbsp; put_line(&quot;Please enter a number:=20
&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
get(temp);<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
while temp /=3D -99 =
loop<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
p.number :=3D temp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
p :=3D new=20
link_integer;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
last.next :=3D=20
p;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first.number :=3D =

temp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last :=3D=20
p;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
put_line(&quot;Please=20
enter a number: =
&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
get(temp);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
first.number :=3D=20
temp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first.next =
:=3D=20
p;<BR>&nbsp;&nbsp;&nbsp;&nbsp; end loop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>--=20
printing outing the link list<BR>&nbsp;&nbsp; temp :=3D=20
first.number;<BR>&nbsp;&nbsp; while temp /=3D last.number=20
loop<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; put(&quot;The number is=20
&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
put(temp);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp=20
:=3D p.number;<BR>&nbsp;&nbsp; end loop;</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>end testing;</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2>Thanks,<BR>Eric Sabo<BR><A=20
href=3D"mailto:sabo@hhs.net">sabo@hhs.net</A></FONT></DIV></BODY></HTML>

------=_NextPart_000_1BB5_01BD004A.9C960820--




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Please help link list!
  1997-12-04  0:00 Please help link list! Eric Sabo
@ 1997-12-05  0:00 ` Jerry van Dijk
  1997-12-05  0:00 ` bklungle
  1 sibling, 0 replies; 3+ messages in thread
From: Jerry van Dijk @ 1997-12-05  0:00 UTC (permalink / raw)



In article <01bd0074$856c1020$8d484893@default> sabo@HHS.NET writes:

>What am I doing wrong with this program?

Three remarks up-front:

1) Disable HTML in your mailer, as this is very hard to read using an
   ascii based mailer

2) Use one of the standard Ada styles for writing code, this makes it
   much more readable for others

3) GNAT.IO is a gnat specific package, use the language standard IO
   packages

Technically speaking you are doing nothing wrong with the program, when
compiled it does exactly what you instructed it to do.

Probably you mean it is not doing what you intended it to do. As this
looks like an assigment, best thing to do is ask you instructor for
help.

If your assignment is to program a linked list, this is coming quite
close, but the program contains several logic errors.

A old-fashioned technique I find very useful for finding errors like
this is to print out the program, take a blank sheet of paper, and
execute it yourself.

That is, write down the variables starting values, enter a number,
follow the program, writing down the new values of the variables as they
are updated. After a few iterations, check if the values the variables
are assigned to are what you expected them to be.

--

-- Jerry van Dijk | Leiden, Holland
-- Consultant     | Team Ada
-- Ordina Finance | jdijk@acm.org




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Please help link list!
  1997-12-04  0:00 Please help link list! Eric Sabo
  1997-12-05  0:00 ` Jerry van Dijk
@ 1997-12-05  0:00 ` bklungle
  1 sibling, 0 replies; 3+ messages in thread
From: bklungle @ 1997-12-05  0:00 UTC (permalink / raw)



This is a multi-part message in MIME format.

------=_NextPart_000_0026_01BD0124.8F17E440
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I  am afraid I have to agree with Jerry Van Dijk. I had your code =
rewritten and working and ready to send it to you, along with the pseudo =
code (structured english statements) for it. I read Jerry's comment and =
decided it wasn't fair to do your work for you. As a hint, you started =
out ok, then seem to have forgotten what a link list is, or you are =
trying to design on the terminal using code. Unless you are an expert in =
a language, you shouldn't do this. Draw a detailed flowchart, or do a =
Nassi-Schneiderman, or write a pseudo-code detailed description of the =
steps, or do it in spanish, or, ...; remember, your instructor is your =
best friend in this endeaver. Incidentally, every book I have ever seen =
on Ada, Pascal, C, etc has code in it to do almost exactly what you are =
doing.=20

cheers...bob
Eric Sabo wrote in message <01bd0074$856c1020$8d484893@default>...
    What am I doing wrong with this program?
    with gnat.io; use gnat.io;
    procedure testing is
    type link_integer;
    type pointer is access link_integer;
    type link_integer is
       record
          number : integer;
          next : pointer;
       end record;=20
    first, last, p : pointer;
    temp : integer;
    begin
        =20
         put("Project Number two");
         p :=3D new link_integer;
         first :=3D p;
         last :=3D p;
    -- Entering the link list
         put_line("Please enter a number: ");
         get(temp);
         while temp /=3D -99 loop
             p.number :=3D temp;
             p :=3D new link_integer;
             last.next :=3D p;
             first.number :=3D temp;
             last :=3D p;
             put_line("Please enter a number: ");
             get(temp);
             first.number :=3D temp;
             first.next :=3D p;
         end loop;     =20
    -- printing outing the link list
       temp :=3D first.number;
       while temp /=3D last.number loop
          put("The number is ");
          put(temp);     =20
          temp :=3D p.number;
       end loop;=20
    end testing;
    =20
    Thanks,
    Eric Sabo
    sabo@hhs.net

------=_NextPart_000_0026_01BD0124.8F17E440
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 =
HTML//EN">
<META content=3D'"MSHTML 4.71.1712.3"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 size=3D2>I&nbsp; am afraid I have to agree =
with Jerry Van=20
Dijk. I had your code rewritten and working and ready to send it to you, =
along=20
with the pseudo code (structured english statements) for it. I read =
Jerry's=20
comment and decided it wasn't fair to do your work for you. As a hint, =
you=20
started out ok, then seem to have forgotten what a link list is, or you =
are=20
trying to design on the terminal using code. Unless you are an expert in =
a=20
language, you shouldn't do this. Draw a detailed flowchart, or do a=20
Nassi-Schneiderman, or write a pseudo-code detailed description of the =
steps, or=20
do it in spanish, or, ...; remember, your instructor is your best friend =
in this=20
endeaver. Incidentally, every book I have ever seen on Ada, Pascal, C, =
etc has=20
code in it to do almost exactly what you are doing. </FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>cheers...bob</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 solid 2px; MARGIN-LEFT: 5px; PADDING-LEFT: =
5px">
    <DIV>Eric Sabo<SABO@HHS.NET> wrote in message=20
    &lt;01bd0074$856c1020$8d484893@default&gt;...</DIV>
    <DIV><FONT color=3D#000000 size=3D2>What am I doing wrong with this=20
    program?</FONT></DIV>
    <DIV><FONT color=3D#000000 size=3D2></FONT><FONT size=3D2>with =
gnat.io; use=20
    gnat.io;<BR>procedure testing is<BR>type link_integer;<BR>type =
pointer is=20
    access link_integer;<BR>type link_integer is<BR>&nbsp;&nbsp;=20
    record<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number :=20
    integer;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; next : =
pointer;<BR>&nbsp;&nbsp;=20
    end record;</FONT>&nbsp;</DIV>
    <DIV><FONT size=3D2>first, last, p : pointer;<BR>temp :=20
    integer;<BR>begin<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
    put(&quot;Project Number two&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp; p =
:=3D new=20
    link_integer;<BR>&nbsp;&nbsp;&nbsp;&nbsp; first :=3D=20
    p;<BR>&nbsp;&nbsp;&nbsp;&nbsp; last :=3D p;<BR>-- Entering the link=20
    list<BR>&nbsp;&nbsp;&nbsp;&nbsp; put_line(&quot;Please enter a =
number:=20
    &quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
get(temp);<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
    while temp /=3D -99 =
loop<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    p.number :=3D =
temp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p :=3D=20
    new =
link_integer;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    last.next :=3D =
p;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    first.number :=3D =
temp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    last :=3D p;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    put_line(&quot;Please enter a number:=20
    &quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    get(temp);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
first.number=20
    :=3D temp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
first.next :=3D=20
    p;<BR>&nbsp;&nbsp;&nbsp;&nbsp; end =
loop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    <BR>-- printing outing the link list<BR>&nbsp;&nbsp; temp :=3D=20
    first.number;<BR>&nbsp;&nbsp; while temp /=3D last.number=20
    loop<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; put(&quot;The number is=20
    &quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    put(temp);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    temp :=3D p.number;<BR>&nbsp;&nbsp; end loop;</FONT>&nbsp;</DIV>
    <DIV><FONT size=3D2>end testing;</FONT></DIV>
    <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT color=3D#000000 size=3D2>Thanks,<BR>Eric Sabo<BR><A=20
    =
href=3D"mailto:sabo@hhs.net">sabo@hhs.net</A></FONT></DIV></BLOCKQUOTE></=
BODY></HTML>

------=_NextPart_000_0026_01BD0124.8F17E440--





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-12-05  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-04  0:00 Please help link list! Eric Sabo
1997-12-05  0:00 ` Jerry van Dijk
1997-12-05  0:00 ` bklungle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox