Advertisement
avr39ripe

numberGuess

Jul 17th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3.  
  4. int main()
  5. {
  6.     int secret{ 0 };
  7.     int guess{ 0 };
  8.  
  9.     srand(time(0));
  10.     secret = rand() % 51;
  11.  
  12.     std::cout << "Try to guess my number from 1 to 50\n";
  13.     do
  14.     {
  15.         std::cout << "Enter your number...\n";
  16.         std::cin >> guess;
  17.         if (guess == secret)
  18.         {
  19.             std::cout << "Wow! You did it! Secret number was " << secret << ". Well done!\n";
  20.         }
  21.         if (guess > secret)
  22.         {
  23.             std::cout << "My number is smaller than yours! Try again!\n";
  24.         }
  25.         else
  26.         {
  27.             std::cout << "My number is greater than yours! Try again!\n";
  28.         }
  29.     } while (guess != secret);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement