Created
January 21, 2016 02:00
-
-
Save Heasummn/b50f84101f198dbf41d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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