#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int inGame ();
int main()
{
printf("I have a number between 1 and 1000\nCan you guess my number?\nPlease type your first guess\nType e to end.\n\n");
while (inGame () == 1);
printf("Ending Game.\n");
return 0;
}
int inGame ()
{
int in, num;
char end;
printf("Guess: ");
num = 1+(rand ( ) % 1000);
while (scanf("%d", &in) && in != num)
{
if(in < num)
printf("Too low. Try again: ");
else if(in > num)
printf("Too high. Try again: ");
}
printf("Correct!\n");
while (scanf("%c", &end))
{
if (strcmp(&end, "y") == 1)
return 1;
else if (strcmp(&end, "n") == 1)
return 0;
else
printf("Would you like to play again? (y or n) ");
}
return 1;
}