Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int num, rand_num, opc, intentos = 0;// variables = numero insertado, numero random, opcion elejida, contador de intentos
- cout << "Bienvenido! Elija una opcion.\n 1 -Comenzar \n 2 -Salir" << endl;
- cin >> opc;
- if(opc == 1){// si la respuesta es uno
- rand_num = rand() % 100;// nuevo numero random y inicio del bucle(juego)
- do{
- cout << "Elija un numero." << endl;
- cin >> num;
- if(num < rand_num)//si el numero es menor
- {
- intentos++;// suma un intento
- cout << "Ingrese un numero mas alto\n Intentos: " << intentos << endl;// le da una ayuda al usuario
- }else if(num > rand_num)// si es mayor hace lo mismo pero le indica que ingrese un numero mas chico
- {
- intentos++;
- cout << "Ingrese un numero mas chico\n Intentos: " << intentos << endl;
- }else if(num == rand_num)// si es igual
- {
- intentos++;// sumame un intento(se suma porque este seria el intento final)
- cout << "Ganaste! Numero de intentos: " << intentos << endl;// lo felicitas
- cout << "1- Jugar de nuevo\n2-Salir" << endl;// le preguntamos is quiere jugar de nuevo o salir
- intentos = 0;// reseteamos los intentos
- rand_num = rand() % 100;// nuevo numero random
- cin >> opc; // y se almacena en la variable de opciones el numero
- }
- }while(opc == 1);// verifica si la condicion sigue siendo 1(jugar/volver a jugar) y reinicia el juego, sino sale del juego
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement