Created
November 20, 2010 12:46
-
-
Save sa7dse/707795 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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