I would be very grateful if someone could help me out with this one.
I've a program were the user should put in data about dogs, and then be able to write them out on the screen.
PROGRAM inlu5(Input, Output);
TYPE String_15=packed ARRAY[1..15] of CHAR;
hundpekare =^hundtyp;
hundtyp=record
namn : String_15;
ras : String_15;
age : Integer;
vikt : Integer;
next : hundpekare;
END;
VAR first,ny,temp : hundpekare;
continue : Boolean;
kom : Char;
i,antal : Integer;
BEGIN
Writeln('Welcome to dogprogram!');
new(first);
first^.next:=NIL; {pekaren nollstlls}
Write('Name of dog?'); Readln(first^.namn);
Write('Race of dog?'); Readln(first^.ras);
Write('Age of dog?');Readln(first^.age);
Write('Weight of dog?'); Readln(first^.vikt);
continue:=true;
Repeat
BEGIN
Write('Do you want to put in data about another dog?Y/N');
Readln(kom);
CASE kom OF
'Y','y': BEGIN
new(temp);
temp:=first;
Writeln(first^.namn:5,':',first^.ras:5,':',first^.age:2,' first^.'); Writeln(temp^.namn:5,':',temp^.ras:5,':',temp^.age:2,' temp^.');
repeat
BEGIN
Writeln('Loop!');
temp:=temp^.next;
END;
until (temp^.next=NIL);
Write('Name?'); Readln(temp^.next^.namn);
Write('Race?'); Readln(temp^.next^.ras);
Write('Age?');Readln(temp^.next^.age);
Write('Weight?'); Readln(temp^.next^.vikt);
temp:=NIL;
END;
'N','n': continue:=false;
Otherwise
BEGIN
Writeln('Wrong kommando, try again!');
continue:=true;
END;
END;
END;
Until NOT continue;
Writeln(antal);
Write('Do you want to write the register? Y/N:');
Readln(kom);
Case kom of
'Y','y': BEGIN
{ I dont know how to make this correct}
END;
'N','n': Writeln('Bye');
Otherwise Writeln('Wrong kommando. Bye!');
END;
END.
Comments
: I've a program were the user should put in data about dogs, and then be able to write them out on the screen.
:
: PROGRAM inlu5(Input, Output);
: TYPE String_15=packed ARRAY[1..15] of CHAR;
:
: hundpekare =^hundtyp;
:
: hundtyp=record
: namn : String_15;
: ras : String_15;
: age : Integer;
: vikt : Integer;
: next : hundpekare;
: END;
:
:
: VAR first,ny,temp : hundpekare;
: continue : Boolean;
: kom : Char;
: i,antal : Integer;
:
: BEGIN
: Writeln('Welcome to dogprogram!');
:
: new(first);
: first^.next:=NIL; {pekaren nollstlls}
: Write('Name of dog?'); Readln(first^.namn);
: Write('Race of dog?'); Readln(first^.ras);
: Write('Age of dog?');Readln(first^.age);
: Write('Weight of dog?'); Readln(first^.vikt);
:
: continue:=true;
: Repeat
: BEGIN
: Write('Do you want to put in data about another dog?Y/N');
: Readln(kom);
: CASE kom OF
: 'Y','y': BEGIN
:
: new(temp);
: temp:=first;
: Writeln(first^.namn:5,':',first^.ras:5,':',first^.age:2,' first^.'); Writeln(temp^.namn:5,':',temp^.ras:5,':',temp^.age:2,' temp^.');
:
: repeat
: BEGIN
: Writeln('Loop!');
: temp:=temp^.next;
: END;
: until (temp^.next=NIL);
:
: Write('Name?'); Readln(temp^.next^.namn);
: Write('Race?'); Readln(temp^.next^.ras);
: Write('Age?');Readln(temp^.next^.age);
: Write('Weight?'); Readln(temp^.next^.vikt);
: temp:=NIL;
: END;
: 'N','n': continue:=false;
: Otherwise
: BEGIN
: Writeln('Wrong kommando, try again!');
: continue:=true;
: END;
: END;
: END;
: Until NOT continue;
:
: Writeln(antal);
: Write('Do you want to write the register? Y/N:');
: Readln(kom);
: Case kom of
: 'Y','y': BEGIN
: { I dont know how to make this correct}
: END;
: 'N','n': Writeln('Bye');
: Otherwise Writeln('Wrong kommando. Bye!');
: END;
: END.
:
:
Here is a much easier and workable code to ask the user for a certain record:
[code]
: PROGRAM inlu5(Input, Output);
: TYPE String_15=packed ARRAY[1..15] of CHAR;
:
: hundpekare =^hundtyp;
:
: hundtyp=record
: namn : String_15;
: ras : String_15;
: age : Integer;
: vikt : Integer;
: next : hundpekare;
: END;
:
:
: VAR first,ny,temp : hundpekare;
: continue : Boolean;
: kom : Char;
: i,antal : Integer;
:
: BEGIN
: Writeln('Welcome to dogprogram!');
:
: new(first);
: first^.next:=NIL; {pekaren nollstlls}
: Write('Name of dog?'); Readln(first^.namn);
: Write('Race of dog?'); Readln(first^.ras);
: Write('Age of dog?');Readln(first^.age);
: Write('Weight of dog?'); Readln(first^.vikt);
Temp := First; { Get the "last" valid record }
Repeat
: Write('Do you want to put in data about another dog?Y/N');
: Readln(kom);
CASE kom OF
'Y','y': BEGIN
New(Temp^.next); { Create a new record beyond the last }
Temp^.Next^.Next := nil;
Write('Name?'); Readln(temp^.next^.namn);
Write('Race?'); Readln(temp^.next^.ras);
Write('Age?');Readln(temp^.next^.age);
Write('Weight?'); Readln(temp^.next^.vikt);
Temp := Temp^.Next; { Update the last record }
end;
until kom in ['n','N']; { End the loop }
: Write('Do you want to write the register? Y/N:');
: Readln(kom);
: Case kom of
: 'Y','y': BEGIN
Temp := First; { Set an index-pointer to the first }
repeat
Writeln(Temp^.namn:5, ':', Temp^.ras:5, ':', Temp^.age:2, ':', Temp^.vikt); { write the current record }
Temp := Temp^.Next; { move to the next record }
until Temp=nil { loop until the end of the list }
END;
: 'N','n': Writeln('Bye');
: Otherwise Writeln('Wrong kommando. Bye!');
: END;
: END.
[/code]
This code takes the "First"-pointer to be the head of the list. If you change this pointer, you will lose the entire list. The "Temp"-pointer is in the input loop the last record in the list, and the "Temp^.Next" is the record to be added to the list. In the output loop it is an index to the current record.
: : I've a program were the user should put in data about dogs, and then be able to write them out on the screen.
: :
: : PROGRAM inlu5(Input, Output);
: : TYPE String_15=packed ARRAY[1..15] of CHAR;
: :
: : hundpekare =^hundtyp;
: :
: : hundtyp=record
: : namn : String_15;
: : ras : String_15;
: : age : Integer;
: : vikt : Integer;
: : next : hundpekare;
: : END;
: :
: :
: : VAR first,ny,temp : hundpekare;
: : continue : Boolean;
: : kom : Char;
: : i,antal : Integer;
: :
: : BEGIN
: : Writeln('Welcome to dogprogram!');
: :
: : new(first);
: : first^.next:=NIL; {pekaren nollstlls}
: : Write('Name of dog?'); Readln(first^.namn);
: : Write('Race of dog?'); Readln(first^.ras);
: : Write('Age of dog?');Readln(first^.age);
: : Write('Weight of dog?'); Readln(first^.vikt);
: :
: : continue:=true;
: : Repeat
: : BEGIN
: : Write('Do you want to put in data about another dog?Y/N');
: : Readln(kom);
: : CASE kom OF
: : 'Y','y': BEGIN
: :
: : new(temp);
: : temp:=first;
: : Writeln(first^.namn:5,':',first^.ras:5,':',first^.age:2,' first^.'); Writeln(temp^.namn:5,':',temp^.ras:5,':',temp^.age:2,' temp^.');
: :
: : repeat
: : BEGIN
: : Writeln('Loop!');
: : temp:=temp^.next;
: : END;
: : until (temp^.next=NIL);
: :
: : Write('Name?'); Readln(temp^.next^.namn);
: : Write('Race?'); Readln(temp^.next^.ras);
: : Write('Age?');Readln(temp^.next^.age);
: : Write('Weight?'); Readln(temp^.next^.vikt);
: : temp:=NIL;
: : END;
: : 'N','n': continue:=false;
: : Otherwise
: : BEGIN
: : Writeln('Wrong kommando, try again!');
: : continue:=true;
: : END;
: : END;
: : END;
: : Until NOT continue;
: :
: : Writeln(antal);
: : Write('Do you want to write the register? Y/N:');
: : Readln(kom);
: : Case kom of
: : 'Y','y': BEGIN
: : { I dont know how to make this correct}
: : END;
: : 'N','n': Writeln('Bye');
: : Otherwise Writeln('Wrong kommando. Bye!');
: : END;
: : END.
: :
: :
: Here is a much easier and workable code to ask the user for a certain record:
: [code]
: : PROGRAM inlu5(Input, Output);
: : TYPE String_15=packed ARRAY[1..15] of CHAR;
: :
: : hundpekare =^hundtyp;
: :
: : hundtyp=record
: : namn : String_15;
: : ras : String_15;
: : age : Integer;
: : vikt : Integer;
: : next : hundpekare;
: : END;
: :
: :
: : VAR first,ny,temp : hundpekare;
: : continue : Boolean;
: : kom : Char;
: : i,antal : Integer;
: :
: : BEGIN
: : Writeln('Welcome to dogprogram!');
: :
: : new(first);
: : first^.next:=NIL; {pekaren nollstlls}
: : Write('Name of dog?'); Readln(first^.namn);
: : Write('Race of dog?'); Readln(first^.ras);
: : Write('Age of dog?');Readln(first^.age);
: : Write('Weight of dog?'); Readln(first^.vikt);
: Temp := First; { Get the "last" valid record }
: Repeat
: : Write('Do you want to put in data about another dog?Y/N');
: : Readln(kom);
: CASE kom OF
: 'Y','y': BEGIN
: New(Temp^.next); { Create a new record beyond the last }
: Temp^.Next^.Next := nil;
: Write('Name?'); Readln(temp^.next^.namn);
: Write('Race?'); Readln(temp^.next^.ras);
: Write('Age?');Readln(temp^.next^.age);
: Write('Weight?'); Readln(temp^.next^.vikt);
: Temp := Temp^.Next; { Update the last record }
: end;
: until kom in ['n','N']; { End the loop }
: : Write('Do you want to write the register? Y/N:');
: : Readln(kom);
: : Case kom of
: : 'Y','y': BEGIN
: Temp := First; { Set an index-pointer to the first }
: repeat
: Writeln(Temp^.namn:5, ':', Temp^.ras:5, ':', Temp^.age:2, ':', Temp^.vikt); { write the current record }
: Temp := Temp^.Next; { move to the next record }
: until Temp=nil { loop until the end of the list }
: END;
: : 'N','n': Writeln('Bye');
: : Otherwise Writeln('Wrong kommando. Bye!');
: : END;
: : END.
: [/code]
: This code takes the "First"-pointer to be the head of the list. If you change this pointer, you will lose the entire list. The "Temp"-pointer is in the input loop the last record in the list, and the "Temp^.Next" is the record to be added to the list. In the output loop it is an index to the current record.
:
Many Thanx!