Hello!
I'm making a hangman game in Pascal for a study project and I'm having trouble with this part.
Let's say the word is "mom", if the player wants to guess the letter "m" the program should return that the letter "m" is in the 1st and 3rd position.
The code used to find elements in the array is the following:
repeat
c := c+1
until (word[c] = letter) or (c >= wordlength);
position := c;
if (word[c] = letter)
then
begin
repeat
z:=z+1
until (correct[z] = letter) or (z >= wordlength);
if correct[z] = letter
then
begin
writeln('This letter has already been guessed correctly')
end
else
begin
correctAmout := correctAmount+1;
correct[position] := letter;
writeln('CORRECT!');
WriteLn;
for y := 1 to wordlenght do
Write(correct[y]);
end;
end
...
Being "word" the array that contains the original word and "correct" the array that contains the already correctly guessed letters.
Obviously this code is wrong because it jumps out of the searching process as soon as it founds a match, which is not good.
I tried a few things and couldn't get it working and have absolutely no idea how to make this right.
If anyone has an idea, I would be very welcome!
EDIT: If you need I can upload the source code file, but it's in spanish. It shouldn't be much problem since it's just the variables that have names in other language, but hey, it might be a little bit harder to understand than one in English