Code Wars V
     

Program / Task Name:

   Hangman

Level:

 

 Novice

Point Value:

 

 4

 

Task Description

Create a computerized version of the game of “hangman”. The judge will specify both the solution for the game and the letter guesses for the game. Your program must determine if the judge has won or lost the game (based on the letter guesses) and draw the traditional hangman picture as follows:

1st Wrong Guess: “ O” <<Carriage Return>>
2nd Wrong Guess: “/ “
3rd Wrong Guess: “| “
4th Wrong Guess: “ \” <<Carriage Return>>
5th Wrong Guess: “ / “
6th Wrong Guess: “ \” <<Carriage Return>>
 

Some languages use the “\” character as a control character.  If you’re using one of the languages please make the appropriate adjustments in the code (i.e. C and C++ use this “\\” to represent this “\”).

Program Input

Your program should print a prompt for the judge to enter a solution. Then prompt the judge for the letter guesses (all on 1 line). You can assume that:

  • All solutions will be either 1 or 2 words,
  • No solution will be longer than 20 letters in length (including the space between the words),
  • The judge will specify enough letter guesses to either win or lose the game,
  • All letter guesses are case insensitive (treat ‘a’ and ‘A” as the same letter), and
  • No numbers will be entered,
  • No letter guess will be entered more than once,
  • Only 1 solution will be specified per game (running of the program).

Since the judge is specifying all of the letter guesses on a single line, ignore all letter guesses after the 6th incorrect guess.

Please enter solution: Wayne Gretzky
Please enter your guesses: aeioubtwgsynzkr
 

Program Output

After reading both the solution and letter guesses, your program must determine if the judge has won (You Won!) or lost (You Lost!) the game and print out the current state of the hangman.

You Won!
 O
/|\
/
 

 

hp Code Wars
Hello -- Dominos?...
   
  (c) 2004 Hewlett-Packard Company