Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> // cout, cin
- #include <stdlib.h> // rand(), srand()
- #include <time.h> // time()
- using namespace std;
- int main()
- {
- int n_gen = 0;
- int n_ins = 0;
- int intentos = 6;
- bool adivinar;
- adivinar = true;
- while (adivinar) {
- adivinar = false;
- srand (time(NULL));
- n_gen = rand() % 100 + 1;
- do
- {
- cout << "Adivina el número del 1 al 100 (Intentos disponibles: "
- << intentos << "): ";
- cin >> n_ins;
- if(n_ins == n_gen)
- {
- cout << "Felicidades! has adivinado!!!" << endl;
- }
- else if(n_ins < n_gen)
- {
- cout << "El número es mayor" << endl;
- intentos--;
- }
- else if(n_ins > n_gen)
- {
- cout << "El número es menor" << endl;
- intentos--;
- }
- if(intentos == 0)
- {
- cout << "Lo siento, el número era: " << n_gen
- << ". Mejor suerte para la próxima!" << endl;
- }
- }while(n_ins != n_gen && intentos > 0);
- cout << "Quieres jugar otra vez? s/n: ";
- char res; // single character response. can validate input but i dont thinky ou need to
- cin >> res;
- if (res == 's') {
- adivinar = true;
- intentos = 6;
- }
- }
- cout << "Se ha finalizado el juego. Hasta luego!";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement