What's the relevance in asking "Is your number 50?" if you chose, say, 20? Besides, if you lie to the program and say your number is out of the specified range, the program will get stuck somewhere and ask something like "Is your number 27?" over and over again. Otherwise, nice program.
"Stephen Wolfram is the creator of Mathematica and is widely regarded as the most important innovator in scientific and technical computing today." - Stephen Wolfram
What's the relevance in asking "Is your number 50?" if you chose, say, 20? Besides, if you lie to the program and say your number is out of the specified range, the program will get stuck somewhere and ask something like "Is your number 27?" over and over again. Otherwise, nice program.
Yeah lol, I told the person this, but he said it was good enough :P
I poked around with a different, lazier version of the number guessing game which does a lot of checking.
Code:
#include <iostream.h>
#include <string.h>
#include <math.h>
int main(){
int counter=1, number=1, lasttry=1, looplimit=0;
double increment=50, step=25;
char choice[50];
cout << "Input a number (1-100): ";
cin >> number;
while(increment!=number){
lasttry=increment;
if(increment>100||increment<1||looplimit>4){
cout << "You cheated, you gotta tell me the truth son!\n";
return 0;
}
cout << "You say the number isn't " << increment << ", so is it [H]igher or [L]ower than it? ";
cin >> choice;
if(choice[0]=='h' || choice[0]=='H'){
increment+=step;
if(lasttry==increment){
increment++;
looplimit++;
}
step/=2;
step=floor(step);
counter++;
}
else{
increment-=step;
if(lasttry==increment){
increment--;
looplimit++;
}
step/=2;
step=floor(step);
counter++;
}
}
if(number==50){
cout << "The computer instantly guessed that your number was 50.\n";
return 0;
}
cout << "I guess the number you thought about is " << increment << ", and I WIN!\n";
cout << "It took the computer a total of " << counter << " tries to guess your number.\n";
return 0;
}
"Stephen Wolfram is the creator of Mathematica and is widely regarded as the most important innovator in scientific and technical computing today." - Stephen Wolfram
Yeah, like if someone would type in "higher" instead of 'h'.
"Stephen Wolfram is the creator of Mathematica and is widely regarded as the most important innovator in scientific and technical computing today." - Stephen Wolfram