#include <stdio.h>
#include <conio.h>
#include <string.h>

#define TRUE 1
#define FALSE 0
int hang(void); //declarator

char word[81], dupl[81], hint[81],hint1[81];   //Global Variables Declaration
int a,c;
int chances;
int flag = 0;

void main(void)
{
 clrscr();
 printf ( "Enter the desired word:\n");
 gets(word);                          //gets a word for string 'word'
/* printf ( "Please give the first hint:\n");
 gets(hint1);
 printf ("Enter the second hint:\n");
 gets(hint1); */
 printf ( "Enter the third hint:\n");
 gets(hint);
 printf ( "Enter the number of chances you want to give:" );
 scanf ( "%d", &chances); // user enters no. of chances
 int totalChances = chances; //storing original chances in another variable
 clrscr();

 for ( a = 0; a < strlen(word); a++)
	  {
		dupl[a] = '*';               //prints * equivalent to char in string
	  }
 dupl[strlen(word)] = NULL; //places null character at the end of string
 printf ("%s", dupl);
 printf ("\nYour hint is :\n%s", hint);
 hang();

 if (flag == 1) // ,prints this if win
 {
  printf ( "\nhip hip HURRAY!");
  printf ( "\nYour total score out of hundred is : %.0f ", (((float) chances/(float)totalChances)*100));//prints score out of hundred
 }
 else //prints this if looses
 {
  printf ( "\nGAME OVER!" );
 }
 getch();
}

//definition of function hang
int hang(void)
 {
  while (1) //infinite loop
 {
  int charMatch = FALSE;  //declaration
  printf("\nYou have %d chances ! Enter a letter: ", chances);
  printf("\nIf you want to quit in the middle of game press '/'");
  char b = getch();
  clrscr();

  if ( b == '/')   // to quit in the middle of game
	  {
		printf ( " bye bye ");
		break;
	  }

  for (c = 0; c < strlen(word); c++)  // here the char entered will replace *
		{
		  if (b == word[c])  //comparison
			 {
				dupl[c] = b;  //assignment to a duplicate string
				charMatch = TRUE;
			 }
		}
  printf("%s", dupl);   //displaying of duplicate string
  printf("\nYour hint is:\n%s",hint);
  if (charMatch == FALSE)
  {
	 chances--;  // here chances will decrease
  }
  if (strcmp(word, dupl) == 0) // if word is guessed the loop will break
  {
	flag = 1;
	break;
  }
  else
  if (chances == 0) // if word is not guessed then loop will break here
  {
	flag = 0;
	break;
  }

 }
 return (flag); // returning the value of flag to hang call function
 }

