SHARE
TWEET

Untitled

a guest Feb 9th, 2012 313 Never
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <cctype>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.   cout << "PICK AN INTEGER BETWEEN 1 AND 100 INCLUSIVE, PEON" << endl;
  10.   int low = 1, high = 100;
  11.   while (true) {
  12.     int guess = (low + high) / 2;
  13.     cout << "is ur number " << guess << "? [Yes/Higher/Lower]" << endl;
  14.     string response;
  15.     getline(cin, response);
  16.     if (response.empty()) continue; // wut
  17.     if (tolower(response[0]) == 'y') { cout << "YUP I WINZ"; break; }
  18.     if (tolower(response[0]) == 'h') { low = guess + 1; }
  19.     if (tolower(response[0]) == 'l') { high = guess - 1; }
  20.   }
  21. }
RAW Paste Data
Top