I don't understand why my linear search program in pascal is not working... Some help will be appreciated.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

Type
  TStudent = Record
                Name : String[15];
                  End;

Var Name : array [0..3] of string=('Fred','Jack','Chris','Ali');
    inputname : string;
    n : integer;


begin
Name[0] := 'Fred';
Name[1] := 'Jack';
Name[2] := 'Chris';
Name[3] := 'Ali';

n := 0;

  Writeln('Enter Name');Read(inputname);

  repeat
  If inputname = Name[n]
    then
      writeln(n)
    else
      n := n + 1;

  until inputname = Name[n] ;
  readln;

  If n = 4
    then
    writeln('record not found');

  readln;
end.

Fixed version.Good luck :)

Program Solution;

{$APPTYPE CONSOLE}

Uses
  SysUtils;

Type   //new type
  TStudent = Record
                //with only one field
                RName:String[15];
             End;

Var Name:array[0..3]of TStudent;
    inputname:string[15];
    n:integer;

Begin {the beginning of the main program}
  {fill the array with names}
  Name[0].RName:='Fred'; //dont forget that this is array of TStudent
  Name[1].RName:='Jack';
  Name[2].RName:='Chris';
  Name[3].RName:='Ali';
  n := 0; {beginner value of 'n'}
  Repeat
    {ask the user round by round}
    Write('Enter Name: ');
    ReadLn(inputname);{catch the answer}
    If (inputname <> Name[n].RName) Then Begin
      WriteLn('Wrong record name!');{if wrong name entered}
    End {first part of 'if'}
    Else Begin
      WriteLn(n);{write its place}
      n:= n + 1; {increase 'n' by 1,it is can be Inc(n) too}
    End;{'if'}
  until n=4;
  WriteLn('Congratulations,you made it!');
  ReadLn;  {waiting for pressing the enter button}
End.{of main}
(*
-= Note by FlamingClaw =-
Listen,when you add  names to  variables,do not add the same,
like your record's field and the array,not good idea.
If you want to reference to a record's field then you have to
do like above.
Or see another example:

Type NewType=Record
               name:String;
               birthday:Integer;
             End;

Var Student:Array[1..2]Of NewType;
    i:Integer;

Begin
   //this will fill the array
   For i:=1 To 2 Do Begin
      Write('Give me the name: ');
      ReadLn(Student[i].name);
      Write('And now give him/her birthday: ');
      ReadLn(Student[i].birthday);
   End;
  //write the results
  For i:=1 To 2 Do WriteLn(Student[i].name,'  ',Student[i].birthday);
  ReadLn;
End.

I hope I can help you


-= Created by FlamingClaw =-
-=2009.04.06=-
*)
This question has already been answered. Start a new discussion instead.