#include <iostream.h>
int elsejunk(int count);
void maingame(); //predeclarations
void main ()
{
start:
maingame();
char istring;
cout<<"Another game?"<<endl;
cout<<"Press Y to play another game"<<endl;
cin>>istring;
if ((istring=='Y')||(istring=='y'))goto start;
}
void maingame()
{
int num1 = 50, div1 = 0, hi = 100, lo = 0;
char istring;
cout<<"Think of an int number between 1 and 100."<<endl;
cout<<"Lets play!"<<endl;
cout<<"To all the questions please answer Y(for yes) or N (for no)..."<<endl;
for (int count=1; count<=20; count++)
{
// goes=++;
cout<<"Is your number "<< num1 <<"?"<<endl; //output
cin>> istring; //get the answer for i string
if ((istring=='Y')||(istring=='y')) //if input = Yes
{
cout<<"Your number is "<< num1 << endl; //Do this
cout<<"It took "<< count <<" to guess this number"<<endl;
break;
}
else if ((istring=='N')||(istring=='n'))
{
cout<<"Is your number higher then "<< num1<<"?"<<endl; //do this
cin>> istring; //get the answer for i string
if ((istring=='Y')||(istring=='y')) //if input = Yes so num1 = higher
{
//Higher code
lo=num1;
div1=(hi-num1)/2;
num1=div1 + num1;
}
else if ((istring=='N')||(istring=='n')) //If input = No
{
//Lower code
hi=num1;
div1=(num1-lo)/2;
num1=num1-div1;
}
else //if input doesn't = yes or no
count = elsejunk(count);
}
else count = elsejunk(count);
}
}
int elsejunk(int count)
{
cout << "In the game please enter only Y (for yes) Or N (for no)!!!!"<<endl;
count--;
return count; //this function just say to press Y or N and decrase the count;
//decreasing count is here because player would press for example w many times
//it would be counted as bad tries for computer... so that's why decraseing count...
//result - only Y or N are counted as tries... hope someone get this

)))
}