Advertisement
Master593

Untitled

Jan 25th, 2022
1,530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <cstdlib> // srand(), rand()
  2. #include <ctime>   // time()
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     cout << "Adivine el numero\n";
  10.     cout << "Escriba un numero entero de 0 a 1000\n";
  11.  
  12.     srand(static_cast<unsigned>(time(NULL)));
  13.     int pensado = rand() % 101;
  14.  
  15.     int dicho;
  16.     while (cin >> dicho)
  17.     {
  18.         if (pensado == dicho)
  19.         {
  20.             cout << "Muy bien has adivinado el numero\n";
  21.             break;
  22.         }
  23.         else if (pensado > dicho)
  24.         {
  25.             cout << "El numero es mayor\n";
  26.         }
  27.         else if (pensado < dicho)
  28.         {
  29.             cout << "El numero es menor\n";
  30.         }
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement