Skip to content

Instantly share code, notes, and snippets.

@sa7dse
Created November 20, 2010 12:46
Show Gist options
  • Save sa7dse/707795 to your computer and use it in GitHub Desktop.
Save sa7dse/707795 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int ask()
{
int number;
char nice [256];
printf ("Enter a number: ");
fgets ( nice, 256, stdin );
number = atoi (nice);
return(number);
}
bool Check(int& ans,int& ran)
{
if(ans==ran)
{
return true;
}
else
{
return false;
}
}
int main ()
{
int randint;
int answer;
srand (time(0));
printf("Generating a randome Number...\n");
sleep(5);
randint = rand() % 100 + 1;
int i;
i = 0;
while (1)
{
i ++ ;
answer = ask();
if (Check(answer, randint))
{
printf("Yes thats it baby \n");
printf("You needed %d tries",i);
return 0;
}
else
{
if (answer > randint)
{
printf("Too high Dude! \n");
}
if (answer < randint)
{
printf("Too low Dude! \n");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment