-
Notifications
You must be signed in to change notification settings - Fork 0
/
try.cpp
87 lines (75 loc) · 2.19 KB
/
try.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,j,c,count=0,ans=0,flag=0,*ptr;
char a[1][6]={"dogodo"};
char b[10],alpha;
char d='_';
clrscr();
c=strlen(&a[0][0]);
//printf("\n\t\t**************\n\n\t\t\t");
printf("\n\n\t\t\t ** HANGMAN ** \n");
printf("\n\t\t\t**************\t\t\t");
printf("\n\t\t\t..............\n\n\t\t\t ");
for(j=0;j<c;j++)
{ printf("%c ",d);
b[j]=d;}
//printf("\n\n\t\t*****************");
printf("\n\n\t\t\t..............\t\t\t");
printf("\n\n\t\t\t**************");
// for(j=0;j<c;j++) printf("\n %c",b[j]); //{ ptr=&b[j];
// printf("\n %c",*ptr); }
while (count<6)//||(ans<c))
{
flag=0;
printf("\n\n\n\n\n\n\t enter a char");
alpha=getche();
// printf("%c",alpha);
for(i=0;i<c;i++)
{
if (alpha==a[0][i])
{ b[i]=a[0][i];
flag=1;
ans++; }
//else if(b[i]!=d) b[i]=a[0][i];
//else b[i]=d;
// printf("\n u r correct"); }
// if(ans==c) goto man; }
//printf("\n ans=%d",ans);}
//printf("\n count=%d",count);
}
clrscr();
printf("\n\n\t\t\t ** HANGMAN ** \n");
printf("\n\t\t\t**************\t\t\t");
printf("\n\t\t\t..............\n\n\t\t\t ");
for(i=0;i<c;i++)
printf("%c ",b[i]);
printf("\n\n\t\t\t..............\t\t\t");
printf("\n\n\t\t\t**************");
if(flag==0)
{count++;
printf("\n\n\n\n\t\t%c is a wrong guess",alpha);
printf("\n\n\t\t (u have %d more guesses)",6-count);}
else{
printf("\n\n\t\t u r correct!!");
printf("\n\t\t( u have %d more words to go)",c-ans);}
// printf("\n ans=%d",ans);
// printf("\n count=%d",count);
if(ans==c) break;
}
if(ans==c) printf("\n\n\n\t you won");
else printf("\n\n\n\t\t u lose.\n\n \t\t **SORRY U R HANGED**");
/* if(output[i]!='_')
output[i]=a[0][i];
elseif(b[j]==a[0][i])
output[i]==a[0][i];
else
output[i]='_';
}
for(i=0;i<c;i++)
printf("%c",output[i])
} */
getch();
}