Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 9th, 2012  |  syntax: None  |  size: 0.60 KB  |  views: 271  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data