fork download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. int L = 0;
  6. int R = 101;
  7. char spell = true;
  8. std::cout << "Is the number you thought of larger than (please, input 'y', 'n' or '=') " << 50 << "? ";
  9. while (std::cin >> spell)
  10. {
  11. if (spell != 'y' && spell != 'n' && spell != '=')
  12. {
  13. std::cout << "Please, input 'y', 'n' or '=': " << std::endl;
  14. continue;
  15. }
  16.  
  17. int M = (L + R) / 2;
  18.  
  19. if (spell == '=')
  20. {
  21. std::cout << "The number you thought of is " << M << "!" << std::endl;
  22. break;
  23. }
  24.  
  25. switch (spell)
  26. {
  27. case 'y':
  28. {
  29. L = M;
  30. break;
  31. }
  32. case 'n':
  33. {
  34. R = M;
  35. break;
  36. }
  37. }
  38.  
  39. M = (L + R) / 2;
  40.  
  41. std::cout << "Is the number you thought of larger than " << M << "? ";
  42. }
  43. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Is the number you thought of larger than (please, input 'y', 'n' or '=') 50?