Hello every one I'm trying to write a game that has a person guess a number between 1 and 100 hand have the computer guess that number via inputs from the user but I keep running into snags.
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main()
{
srand ((unsigned)time(0));
int num, x, y, z;
char ans, ans2;
cout<<"Please pick a number between 1 and 100, are you ready \n";
cout<<"to begin? y or n"<<endl;
cin>>ans;
if (ans!='n')
{
do
{
y=100;
z=1;
x= rand () % y + z;
cout<<"Is your number higher or lower then "<<x<<" or neither."<<endl;
cin>>ans;
if(ans=='h')
{
z = z -(y-x);
y = x;
}
if (ans=='l')
z=x-z;
}while (ans!='n');
cout<<"Is your number: "<<x<<endl;
}
return 0;
}
I'm trying to have the PRNG narrow down its search perimeters with every entry from the user but every time I change something and think that I have fixed the problem the game does something that is unexpected.... it is driving me batty any help would be much appreciated.