/****************************************************
Write a simple version of hangman, in which the user
enters the word he'll "guess", and then the user gets
to start guessing letters. After each guess, the word
is printed out with *s instead of unguessed letters.
 ****************************************************/
#include <iostream>
#include <string>

int main()
{
  // Get word to guess
  string s;
  cout << "Enter word to guess: ";
  cin >> s;
  
  // Set the mask array - mask[i] is true if the
  // character s[i] has been guessed.  The mask
  // must be allocated, and initialized to all false
  int N = s.length();
  bool *mask = new bool[N];
  for(int i = 0; i < N; i++)
    mask[i] = false;

  // Loop over each round of guessing
  bool winflag;
  do {
    // Print word with *s for unguessed letters
    cout << "The word is : ";
    for(int j = 0; j < N; j++)
      if (mask[j])
	cout << s[j];
      else
	cout << '*';
    cout << endl;

    // Get players next guess
    cout << "Letter? ";
    char c;
    cin >> c;

    // Mark true all mask positions corresponding to guess
    for(int k = 0; k < N; k++)
      if (s[k] == c)
	mask[k] = true;

    // Determine whether the player has won!
    winflag = true;
    for(int m = 0; m < N; m++)
      if (!mask[m])
	winflag = false;

  } while(!winflag);

  // Print victory message!
  cout << "Victory! the word is \"" << s << "\"!" << endl;

  return 0;
}