#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
cout<<"Please Think a Number between 0 to 100 in your mind and press enter : ";
getch();
char ug;
int cg=50,high=100,low=0;
clrscr();
while(ug!='=')
{
cout<<"What about : "<<cg;
cin>>ug;
switch(ug)
{
case '<':
{
high=cg-1;
cg=(high+low)/2;
break;
}
case '>':
{
low=cg+1;
cg=(high+low)/2;
break;
}
case '=':
{
cout<<"Your Number is :"<<cg;
break;
}
default:
{
cout<<"Wrong Choice";
}
}
}
getch();
}
#include<conio.h>
main()
{
clrscr();
cout<<"Please Think a Number between 0 to 100 in your mind and press enter : ";
getch();
char ug;
int cg=50,high=100,low=0;
clrscr();
while(ug!='=')
{
cout<<"What about : "<<cg;
cin>>ug;
switch(ug)
{
case '<':
{
high=cg-1;
cg=(high+low)/2;
break;
}
case '>':
{
low=cg+1;
cg=(high+low)/2;
break;
}
case '=':
{
cout<<"Your Number is :"<<cg;
break;
}
default:
{
cout<<"Wrong Choice";
}
}
}
getch();
}
No comments:
Post a Comment