Algorithm for Hangman
- Start
- Identify player 1.
- Identify player 2.
- Player 1 inputs word or phrase.
- Identify length of word or phrase.
- Player 2 starts out with 6 chances to guess a wrong letter.
- While chances > 0,
- Have all the letter been correctly guessed?
- Yes: Player 2 wins!
- End
- No: Player 2 guess a letter.
- Is the letter correct?
- Yes: Print letter and go back to step 8.
- No: Loses a chance.
- How many chances are left?
- 5: Print head.
- Go back to step 8.
- 4: Add torso to head.
- Go back to step 8.
- 3: Add left arm to torso.
- Go back to step 8.
- 2: Add right arm to torso.
- Go back to step 8.
- 1: Add left leg to torso.
- Go back to step 8.
- 0: Add right leg to torso.
- Player 2 loses.
- End
- Player 2 loses.
- 5: Print head.
- How many chances are left?
- Is the letter correct?
- Yes: Player 2 wins!