Skip to content

Instantly share code, notes, and snippets.

@Heasummn
Created January 21, 2016 02:00
Show Gist options
  • Save Heasummn/b50f84101f198dbf41d6 to your computer and use it in GitHub Desktop.
Save Heasummn/b50f84101f198dbf41d6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string.h>
void guessNumber();
bool isSolution(int);
bool tooHigh(int);
int main() {
guessNumber();
}
void guessNumber() {
int currentGuess = 100;
while(!isSolution(currentGuess)) {
if(tooHigh(currentGuess)) {
currentGuess /= 2;
} else {
currentGuess *= 1.5;
}
}
}
bool isSolution(int number) {
std::string answer;
while(answer != "y" && answer != "n") {
std::cout << "Is " << number << " you're number?[y/n] ";
std::getline(std::cin, answer);
}
return answer == "y";
}
bool tooHigh(int number) {
std::string answer;
while(answer != "h" && answer != "l") {
std::cout << "Is " << number << " too high, or too low?[h/l] ";
std::getline(std::cin, answer);
}
return answer == "h";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment