You are on page 1of 5

#include<iostream.

h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>
void tod(int);
int f,g,h,t;
void main()
{
clrscr();
ramsita:
clock_t start,end;
clock_t start1,end1;
int element,i,number,j,k,l,m,numb[10],p[10],q[10],r[10],s[10],cow=0,bull=0;
int z=0;
char ch;
gotoxy(22,1);
cout<<"WELCOME IN NAVPREET AND NEERAJ'S COW & BULL MANIA"<<"\n
(MASTER MIND GAME)\n";
cout<<"In this game computer will have random number which you have to guess the numberto
win.If your guessed number have a same digit with that random one then it is a cow & if position
matches it is a bull.\n";
gotoxy(25,6);
cout<<" *********RULES********* \n";
cout<<"1.Only 7 chance are there to guess.Start when there is 1 at chance column.\n";
cout<<"2.The number contains digits from 0 to 9.\n";
cout<<"3.The number is between 1000 to 9999.\n";
cout<<"4.Any of the digit may not repeated.\n";
cout<<"5.You should not enter any character except (0-9).\n";
cout<<"6.You can't wait more than 3min. for a chance.\n";
cout<<"7.Most important one,if U have broken more then 5 rules you will lose the game.\n";
cout<<"8.Use of any character except of (0-9) will lead to lose of match.\n";
cout<<"CHANCE"<<" "<<"NUMBER"<<" "<<"COW"<<" "<<"BULL"<<"\n";
cout<<"";
nav:
randomize();
number=(rand()%10000);

tod(number);
if(number<1000)
goto nav;
if((f==g)||(f==h)||(f==t)||(g==h)||(g==t)||(h==t))
goto nav;
j=f;
k=g;
l=h;
m=t;
start1=clock();
for(i=0;i<7;i++,cow=0,bull=0)
{
cu:
if(z>4)
{cout<<"YOU HAVE LOST \n";
goto starter;
}
start=clock();
cout<<i+1<<"
";
cin>>numb[i];
end=clock();
if(((end-start)/CLK_TCK)>180)
{cout<<"YOU HAVE LOST \n";
cout<<"THE TIME IS OVER";
goto starter;
}
element=numb[i];
if((element<1000)||(element>9999))
{
z++;
cout<<"a";
gotoxy(1,i+16);
delline();
goto cu;
}
tod(element);

if((f==g)||(f==h)||(f==t)||(g==h)||(g==t)||(h==t))
{
z++;
cout<<"a";
gotoxy(1,i+16);
delline();
goto cu;
}
{p[i]=f;
q[i]=g;
r[i]=h;
s[i]=t; }
{if(j==p[i])
bull++;
if(k==p[i])
cow++;
if(l==p[i])
cow++;
if(m==p[i])
cow++;}
{if(j==q[i])
cow++;
if(k==q[i])
bull++;
if(l==q[i])
cow++;
if(m==q[i])
cow++;}
{if(j==r[i])
cow++;
if(k==r[i])
cow++;
if(l==r[i])
bull++;
if(m==r[i])
cow++;}
{if(j==s[i])
cow++;
if(k==s[i])

cow++;
if(l==s[i])
cow++;
if(m==s[i])
bull++;}

gotoxy(15,(i+16));
cout<<" "<<cow <<"
delline();

"<<bull <<" \n";

if(bull>3)
{cout<<"YOU HAVE WON";
end1=clock();
cout<<"YOU HAVE TAKEN:"<<"\t"<<((end1-start1)/CLK_TCK)<<"secs";
goto starter;
}
if((i==6)&&(bull<4))
{
cout<<"YOU HAVE LOST \n";
goto starter;
}
}
starter:
cout<<"THE ANSWER IS "<<number<<"\n";
cout<<"\n"<<"\n"<<"THaNx FoR PlAyiNg"<<"\n"<<"\n"<<"MADE BY NSD AND NEERAJ
\n";
cout<<"\n"<<"\n"<<"WANNA PLAY MORE (Y-N)\n";
cout<<"";
cout<<"\n";
cin>>ch;
if((ch=='y')||(ch=='Y'))
{clrscr();
gotoxy(1,1);
goto ramsita;
}
if(ch=='n')
exit(0);
getch();
}
void tod(int num)

{
int i,a,b;

for(i=0;i<4;i++)
{
a=(num%10);
b=(num/10);
switch(i)
{
case 0:t=a;
break;
case 1:h=a;
break;
case 2:g=a;
break;
case 3:f=a;
break;
default:
;
}
num=b;
}

You might also like