#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<string>
usingnamespace std;
int main(){
int x,y,z, terminator=0,count;
string user[3]={"lower","higher","correct"};
string me;
srand(time(NULL));
y=100;
z=1;
cout<<"Pick a number between 1 - 100 and I will try to guess it.\n";
while(terminator==0){
int num=3;
x=rand()% y+z;
cout<<"is it "<<x<<" ?";
cin>>me;
for(count=0;count<3;count++){
if(me==user[count]){
num=count;
}
}
switch(num){
case 0:
y=x;
break;
case 1:
z=x;
y=y-z;
break;
case 2:
cout<<"hahaha! I told you I can guess it.";
terminator++;
break;
default :
cout<<"what was that?\n";
break;
}
}
return 0;
}
but encountered a problem.. well it is a problem I can't quite understand. hope you can help me.. thanks..
PS. i have a guess that my problem is my math. am i right?
but encountered a problem.. well it is a problem I can't quite understand. hope you can help me.. thanks..
You'd better tell exactly what your problem is. Telepathes are on vacations, you know.
x=rand()% y+z;
i.e if z = 40 and y = 90, then x could be 129?
was this exactly what you want?
you need rand of their difference added to smaller of them. however you'd better assign to x the average of y and z. Rand is not necessary here...
switch(num){
case 0:
y=x;
break;
case 1:
y=(y+z)-x;
z=x;
break;
case 2:
cout<<"hahaha! I told you I can guess it.";
terminator++;
break;
default :
cout<<"what was that?\n";
break;
}