Advertisement
Mastercpp

adivinar el numero secreto 3

Aug 14th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. void adivinar_numero();
  9.  
  10. void adivinar_numero(){
  11.  
  12.     srand(time(NULL)); // cada vez que se ejecute el programa el valor de a va estar a cambiando
  13.  
  14.     int numero_secreto = rand()%10+1; // uso la libreria math para gener un numero aleatorio
  15.     int intentos= 0; // este sera el numero de intentos  , esta variable tiene un valor de 2  
  16.     //cout << numero_secreto << endl; //no mostremos el numero secreto o no sera secreto XD
  17.  
  18.     int numero_ingresado;
  19.     cout << "Adivina un  numero del 1 al 10: " << endl;
  20.                
  21.     while(intentos<3){
  22.         intentos++;                                  
  23.         cout << "Este es el intento numero " << intentos <<" :";
  24.         cin>>numero_ingresado;
  25.        
  26.          if(numero_ingresado == numero_secreto){
  27.             cout << "Adivinaste el numero" << endl;
  28.             break;
  29.         }
  30.         else if(intentos == 3){
  31.             cout << "perdiste" << endl;
  32.         }
  33.  
  34.     }
  35.  
  36.      
  37.         // aqui le doy al usuario la posiblidad
  38.     int opcion;
  39.     cout << "1-jugar otra vez 2-salir: ";
  40.     cin>>opcion;
  41.     if(opcion == 1){
  42.         adivinar_numero();
  43.     }
  44.     else cout << "adios" << endl;
  45.  
  46. }
  47.  
  48. int main(){
  49.     //int opcion;
  50.     adivinar_numero();
  51.    
  52.  
  53.     cin.get();
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement