I am fairly new to Pascal and I have been attempting to write a hangman game. I am aware that there are probably so many better ways to do this than I have done but I am having some problems where the exit variable is not met because the current variable has a 1 appended to it. As far as I can tell I have not initialised it with a 1 nor can I find anywhere that would append this 1. It is incredibly frustrating and I am completely stumped. Any help would be greatly appreciated.

Program Hangman;

   Procedure Play;

   Var
      used : string;
      current : Array[1..10] of char;
      word : string;
      letter : char;
      i, u, count, count2, word_length, used_length : integer;
      win : boolean;

   Begin

      {set the variables}
      word := 'hello';
      used := '';
      word_length := Length(word);

      win := false;

      for i := 1 to word_length do
      Begin
         current[i] := '-';
      End;

      Repeat

         used_length := Length(used);
         count := 1;
         count2 := 1;

         Writeln;
         Writeln;

         {Display the current word}
         Write('Current Word : ');

         While(count <= word_length) do
         Begin
            Write(current[count]);
            Write(' ');
            count := count + 1;
         End;

         {Display the used letters}
         Writeln;
         Writeln;
         Write('Letters Used : ');

         While(count2 <= used_length) do
         Begin
            Write(used[count2]);
            Write(' ');
            count2 := count2 + 1;
         End;

         Writeln;
         Writeln;
         Write('Pick a letter > ');
         Readln(letter);

         for u := 1 to word_length do
         Begin
            if letter = word[u] then
            Begin
               current[u] := word[u];
            End
         End;

         used := used + letter;

         Writeln(current);
         Writeln(word);
         Writeln(win);

         if current = word then
         Begin
            win := true;
         End;

      Until win;

      Writeln;
      Writeln;
      Writeln;
      Writeln('WIN!!!!');
      Readln;

   End;

   Procedure Menu;

   Var
      input : Integer;

   Begin

      Writeln;
      Writeln('1 : Play');
      Writeln('2 : Word List');
      Writeln('3 : Exit');
      Writeln;
      Write('> ');
      Readln(input);

      case input of
         1: Play();
         {2: Words();}
         3: Exit;

      Else
         Begin
            Writeln('That is not an option.');
            Writeln;
            Menu();
         End;
      End;



   End;

Begin

   Menu();

End.

Have you tried using the debugger to step through the code line by line? Makes it much easier to spot the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.