Hi I'm making a program for a game of Hangman. I have to put a limit to the number of guesses. I have an array to show the current status of the word. So in this array (GuessStatusArray) each cell is either '*', ' ' or a letter guessed correctly eg 'A'.
If someone made a guess of 'O' for the word 'FOOTBALL' then this is how the array would look like. '*OO*****'
The user must have 6 guesses. If they make a correct guess it must not count as one of the six. Therefore after the user guessed 'O' in 'FOOTBALL' they must still have 6 guesses.
Therefore to work out the number of incorrect guesses the user has made I have done IncorrectGuesses := Guesses - CorrectGuesses.
I already have a count for the Guesses else where in the program however I am having trouble working out the correct guesses.
In the code I have done, it goes through each character in the array checking if it is a letter. If it is a letter then the number of Correct Guesses is incremented.
In the example of 'FOOTBALL' above, the code I have done will work the CorrectGuesses to be 2 as the letter O has appeared twice. However the number of correct guesses is actually 1. What do I do to work out the number of correct guesses?
Any help will be appreciated.
(This is only part of the program code that works out the number of incorrect guesses)
Procedure WrongGuesses;
var
CorrectGuesses : Integer;
Index : Integer;
IncorrectGuesses : Integer;
begin
CorrectGuesses := 0;
Index := 1;
repeat
begin
If (GuessStatusArray[Index] >= 'A') and (GuessStatusArray[Index] <= 'Z')
then
Inc(CorrectGuesses);
end;
Inc(Index);
until Index > 20; {The array is from 1 to 20}
IncorrectGuesses := Guesses - CorrectGuesses;
end;