Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <math.h>
- #include <stdlib.h>
- using namespace std;
- void adivinar_numero();
- void adivinar_numero(){
- srand(time(NULL)); // cada vez que se ejecute el programa el valor de a va estar a cambiando
- int numero_secreto = rand()%10+1; // uso la libreria math para gener un numero aleatorio
- int intentos= 0; // este sera el numero de intentos , esta variable tiene un valor de 2
- //cout << numero_secreto << endl; //no mostremos el numero secreto o no sera secreto XD
- int numero_ingresado;
- cout << "Adivina un numero del 1 al 10: " << endl;
- while(intentos<3){
- intentos++;
- cout << "Este es el intento numero " << intentos <<" :";
- cin>>numero_ingresado;
- if(numero_ingresado == numero_secreto){
- cout << "Adivinaste el numero" << endl;
- break;
- }
- else if(intentos == 3){
- cout << "perdiste" << endl;
- }
- }
- // aqui le doy al usuario la posiblidad
- int opcion;
- cout << "1-jugar otra vez 2-salir: ";
- cin>>opcion;
- if(opcion == 1){
- adivinar_numero();
- }
- else cout << "adios" << endl;
- }
- int main(){
- //int opcion;
- adivinar_numero();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement