Skip to content

Instantly share code, notes, and snippets.

@samir96
Created February 14, 2015 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samir96/2dd4e14bfc5912035341 to your computer and use it in GitHub Desktop.
Save samir96/2dd4e14bfc5912035341 to your computer and use it in GitHub Desktop.
Pick a number
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
int numerores, numerointento, intento=0;
srand(time(NULL));
numerores=rand()%100+1;
while(numerores!=numerointento){
intento=intento+1;
cout<<"\nAdivina el numero que estoy pensando entre 1 y 100: ";
cin>>numerointento;
if(numerointento>numerores){
cout<< "\nEste numero es mayor que mi numero "<<endl;
}
if(numerointento<numerores){
cout<< "\nEste numero es menor que mi numero "<<endl;
}
if(numerointento==numerores){
cout<< "\nFelicidades has acertado! "<<endl;
cout<< "\nEl numero de intentos que has realizado para adivinar el numero es de: "<<intento<< " "<<endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment