Tuesday 10 July 2012

Hangman Game in C


#include<stdio.h>
#include<conio.h>


void main()

{

int con,coi;

char a,b,c,d,e,f,g='_',h='_',i='_',j='_',k='_';

 clrscr();

 printf(" enter the five letter word = ");

 printf("\n%c %c %c %c %c\n",g,h,i,j,k);

 a=getch();

 printf("  ");

 b=getch();

 printf("  ");

 c=getch();

 printf("  ");

 d=getch();

 printf("  ");

 e=getch();

 printf("\n\n\nEnter how term u give to player to guess = ");

 scanf("%d",&coi);

 clrscr();



 printf("\n\nEnter the letter for guess = ------- \n");



 for(con=1;con<=coi;con++)

 {
printf("\n\n\tEnter again =  ");
f=getche();

if(f==a)
{
if(g=='_')
{
g=f;

}
}
if(f==b)
{
if(h=='_')
{
h=f;

}
}
if(f==c)


{
if(i=='_')
{
i=f;

}
}
if(f==d)
{
if(j=='_')
{
j=f;

}
}
       if(f==e)
       {
if(k=='_')
{
k=f;
}
       }


  printf("\n\n\n\t%c %c %c %c %c",g,h,i,j,k);



if (a==g&&b==h&&c==i&&d==j&&e==k)
{

printf("\n\n\nYou have won right word is = %c%c%c%c%c",a,b,c,d,e);

break;
}
}



if(g=='_'||h=='_'||i=='_'||j=='_'||k=='_')
  {
  printf("\n\n\nYou have loss it \n\n  right word is = %c%c%c%c%c",a,b,c,d,e);

  }



getche();

}

No comments:

Post a Comment