Advertisement
Guest User

Adivina el número

a guest
Jun 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <windows.h>
  4.  
  5.  
  6. #define limpiar system("cls");
  7. #define pausa system("pause >> void");
  8.  
  9. using namespace std;
  10.  
  11. int main(){
  12.  
  13.  
  14. int opcion, numeroAleatorio, numeroUsuario, vidas;
  15. float probabilidad;
  16.  
  17. menu:
  18.  
  19.     system("title Adivina el numero");
  20.     system("color 0f");
  21.     limpiar;
  22.     vidas=5;
  23.  
  24.     cout << "Adivina el numero" << endl << endl;
  25.     cout << "1. Facil -> (del 1 al 15)" << endl;
  26.     cout << "2. Normal -> (del 1 al 25)" << endl;
  27.     cout << "3. Dificil -> (del 1 al 50)" << endl;
  28.     cout << "Elige la dificultad (escribe el numero): "; cin >> opcion;
  29.  
  30.     switch(opcion) {
  31.  
  32.      case 1:
  33.         limpiar;
  34.         system("title Dificultad facil. 1-15");
  35.         system("color 0A");
  36.         numeroAleatorio = rand() % 15 + 1;
  37.  
  38.         while (vidas > 0)
  39.         {
  40.             limpiar;
  41.             cout << "Escribe un numero: "; cin >> numeroUsuario;
  42.  
  43.             if (numeroUsuario == numeroAleatorio)
  44.             {
  45.                 limpiar;
  46.                 system("title Has ganado.");
  47.                 cout << "Bien! Has adivinado el numero en la dificultad facil." << endl;
  48.                 cout << "Probabilidades de ganar: 33.3%";
  49.                 pausa;
  50.                 goto menu;
  51.             }
  52.             if (numeroUsuario > numeroAleatorio)
  53.             {
  54.                 limpiar;
  55.                 cout << "El numero aleatorio es MENOR que tu numero." << endl;
  56.                 vidas--;
  57.                 cout << "Vidas restantes: " << vidas << endl << endl;
  58.                 cout << "Volviendo..." << endl;
  59.                 Sleep(2000);
  60.             }
  61.             if (numeroUsuario < numeroAleatorio)
  62.             {
  63.                 limpiar;
  64.                 cout << "El numero aleatorio es MAYOR que tu numero." << endl;
  65.                 vidas--;
  66.                 cout << "Vidas restantes: " << vidas << endl << endl;
  67.                 cout << "Volviendo..." << endl;
  68.                 Sleep(2000);
  69.             }
  70.         }
  71.  
  72.         limpiar;
  73.         cout << "Has perdido en la dificultad facil!" << endl;
  74.         cout << "Probabilidades de ganar: 33.3%" << endl << endl;
  75.         cout << "El numero aleatorio era " << numeroAleatorio;
  76.  
  77.     pausa;
  78.     goto menu;
  79.  
  80.         case 2:
  81.         limpiar;
  82.         system("title Dificultad normal. 1-25");
  83.         system("color 0B");
  84.         numeroAleatorio = rand() % 25 + 1;
  85.  
  86.         while (vidas > 0)
  87.         {
  88.             limpiar;
  89.             cout << "Escribe un numero: "; cin >> numeroUsuario;
  90.  
  91.             if (numeroUsuario == numeroAleatorio)
  92.             {
  93.                 limpiar;
  94.                 system("title Has ganado.");
  95.                 cout << "Muy bien! Has adivinado el numero en la dificultad normal." << endl;
  96.                 cout << "Probabilidades de ganar: 20%";
  97.                 pausa;
  98.                 goto menu;
  99.             }
  100.             if (numeroUsuario > numeroAleatorio)
  101.             {
  102.                 limpiar;
  103.                 cout << "El numero aleatorio es MENOR que tu numero." << endl;
  104.                 vidas--;
  105.                 cout << "Vidas restantes: " << vidas << endl << endl;
  106.                 cout << "Volviendo..." << endl;
  107.                 Sleep(2000);
  108.             }
  109.             if (numeroUsuario < numeroAleatorio)
  110.             {
  111.                 limpiar;
  112.                 cout << "El numero aleatorio es MAYOR que tu numero." << endl;
  113.                 vidas--;
  114.                 cout << "Vidas restantes: " << vidas << endl << endl;
  115.                 cout << "Volviendo..." << endl;
  116.                 Sleep(2000);
  117.             }
  118.         }
  119.  
  120.         limpiar;
  121.         cout << "Has perdido!" << endl;
  122.         cout << "Probabilidades de ganar: 20%" << endl << endl;
  123.         cout << "El numero aleatorio era " << numeroAleatorio;
  124.  
  125.         pausa;
  126.         goto menu;
  127.  
  128.          case 3:
  129.         limpiar;
  130.         system("title Dificultad difícil. 1-50");
  131.         system("color 0E");
  132.         numeroAleatorio = rand() % 50 + 1;
  133.  
  134.         while (vidas > 0)
  135.         {
  136.             limpiar;
  137.             cout << "Escribe un numero: "; cin >> numeroUsuario;
  138.  
  139.             if (numeroUsuario == numeroAleatorio)
  140.             {
  141.                 limpiar;
  142.                 system("title Has ganado.");
  143.                 cout << "Felicidades! Has adivinado el numero en la dificultad difícil." << endl;
  144.                 cout << "Probabilidades de ganar: 10%";
  145.                 pausa;
  146.                 goto menu;
  147.             }
  148.             if (numeroUsuario > numeroAleatorio)
  149.             {
  150.                 limpiar;
  151.                 cout << "El numero aleatorio es MENOR que tu numero." << endl;
  152.                 vidas--;
  153.                 cout << "Vidas restantes: " << vidas << endl << endl;
  154.                 cout << "Volviendo..." << endl;
  155.                 Sleep(2000);
  156.             }
  157.             if (numeroUsuario < numeroAleatorio)
  158.             {
  159.                 limpiar;
  160.                 cout << "El numero aleatorio es MAYOR que tu numero." << endl;
  161.                 vidas--;
  162.                 cout << "Vidas restantes: " << vidas << endl << endl;
  163.                 cout << "Volviendo..." << endl;
  164.                 Sleep(2000);
  165.             }
  166.         }
  167.  
  168.         limpiar;
  169.         cout << "Has perdido :(" << endl;
  170.         cout << "Probabilidades de ganar: 10%" << endl << endl;
  171.         cout << "El numero aleatorio era " << numeroAleatorio;
  172.  
  173.         pausa;
  174.         goto menu;
  175.  
  176.  
  177.  
  178.     }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement