-
Notifications
You must be signed in to change notification settings - Fork 0
/
NG.H
149 lines (148 loc) · 2.58 KB
/
NG.H
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using namespace std;
void zcode1()
{
clrscr();
cout<<"\t\t\t\t\tCode Words ";
cout<<"\n\n Leo :- You entered a correct digit but in wrong place ";
cout<<"\n\n Phoenix :- You entered a correct digit in right place ";
cout<<"\n\n Nemesis :- All digits are wrong ";
cout<<"\n\n Zeus :- You got the right number ";
getch();
clrscr();
}
void NG_PL()
{
int mainnum;
char chz;
int yn;
int guess=0;
int win=0;
int n;
int cr;
int a[3],b[3];
char c[3];
int i,j;
randomize();
clrscr();
cout<<" Hello \n\n";
getch();
cout<<" Lets play a number guessing game in which i will think of a 3 digit number and you will try to guess it within 10 attempts .";
getch();
cout<<"\n\n Don't worry it ain't gonna be that tough as you are thinking .";
getch();
clrscr();
cout<<"\n\n After every incorrect attempt i will provide you some hint in code words .";
getch();
cout<<"\n\n So lets first learn about the meaning of these code words .";
getch();
zcode1();
do
{
guess=0;
win=0;
clrscr();
cout<<"\n I have thought of a number .";
n=random(900)+100;
a[0]=n%10;
a[1]=((n%100)-a[0])/10;
a[2]=n/100;
guess=0;
while(guess!=10&&win!=1)
{
clrscr();
yn=0;
cout<<"\n Now try guessing it :- ";
guess++;
cin>>mainnum;
//getch();
i=0;
while(i!=3)
{
c[i]=mainnum%10;
mainnum/=10;
b[i]=c[i];
i++;
}
cout<<endl;
yn=b[0]+b[1]*10+b[2]*100;
cr=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(b[i]==a[j])
{
cr++;
if(i==j)
cout<<" Phoenix ";
else
cout<<" Leo ";
}
if(cr==0)
cout<<" Nemesis ";
cout<<endl;
if(yn==n)
{
cout<<" Zeus ";
win=1;
}
char ch;
cout<<endl;
while(1)
{
getch();
if(guess<3)
{
cout<<" Hope you remember the meaning of our code words if not then press n else press y .";
do
{
cout<<"\nEnter your choice(y/n)";
cin>>ch;
getch();
}while(ch!='n'&&ch!='N'&&ch!='Y'&&ch!='y');
}
if(guess>3)
ch='y';
if(ch=='n'||ch=='N')
{
zcode1();
cr=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(b[i]==a[j])
{
cr++;
if(i==j)
cout<<" Phoenix ";
else
cout<<" Leo ";
}
if(cr==0)
cout<<" Nemesis ";
cout<<endl;
if(yn==n)
cout<<" Zeus ";
cout<<endl;
}
else
break;
}
}
if(win==1)
{
cout<<"\n Congratulation ";
getch();
cout<<"\n You completed the task in "<<guess<<" tries .";
getch();
cout<<"\n Would you like to play again with me to prove that it was not just luck .";
win=0;
}
else
cout<<"Nice try "<<"\n I had thought of "<<n<<"\n Would you like to play once again ? ";
cout<<endl;
do
{
cout<<"\n Enter your choice (y/n):- ";
cin>>chz;
getch();
}while(chz!='n'&&chz!='N'&&chz!='y'&&chz!='Y');
}while(chz=='y'||chz=='Y');
}