avr39ripe

cppMagicNumberGuess

Aug 9th, 2021
657
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     std::cout << "Guess one number from 1 to 63 and I will find it! :()\n";
  6.     uint8_t secretNumber{ 0 };
  7.     int answer{ 0 };
  8.     bool correct{ false };
  9.     for (uint8_t mask{ 1 }; mask < 64; mask <<= 1)
  10.     {
  11.         for (uint8_t number{ 0 }, out{0}; number < 64; ++number)
  12.         {
  13.             if (!((number | mask) == number))
  14.             {
  15.                 std::cout << +(number | mask) << '\t';
  16.                 ++out;
  17.             }
  18.             if (out and out % 8 == 0) { std::cout << "\n\n"; out = 0; }
  19.         }
  20.         std::cout << "\n\n\n";
  21.         do
  22.         {
  23.             std::cout << "Is it on this card? [1 - yes, 0 - no]\n";
  24.             std::cin >> answer;
  25.             correct = (answer == 0 or answer == 1);
  26.             if (!correct) { std::cout << "Invalid input! Try again!\n"; }
  27.         } while (!correct);
  28.         if (answer) { secretNumber += mask; }
  29.     }
  30.     std::cout << "Soooo... Your number is... -> " << +secretNumber << " !!!\n";
  31.     return 0;
  32. }
RAW Paste Data