Guess It in Ansi C
/* ****************************************************************************
C Guessing Game by MystikShadows (Stephane Richard) Public Domain
****************************************************************************
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void main()
{
/* Needed variables for the game */
int  UserGuess;
int  GuessCount;
int  RandomNumber;
char PlayAnother;
int  CanExit;

/* Create a seed for the randum number generator */
srand(time(NULL));
CanExit      = 0;

/* Main loop to play the game */
while (CanExit == 0)
{
/* Assign Default Startup Values */
GuessCount   = 0;
RandomNumber = rand()%100;

printf("\n\nI am thinking of a number between 1 and 100.\n\n");

/* Inner loop To keep on guessing a number */
while (scanf("%d", &UserGuess))
{
if (UserGuess < RandomNumber)
{
printf("Too Small, try a bigger number.\n\n");
GuessCount++;
}
if (UserGuess > RandomNumber)
{
printf("Too big, try a smaller number.\n\n");
GuessCount++;
}
if (UserGuess == RandomNumber)
{
printf("You guess the right number in %d tries.\n\n", GuessCount);
break;
}

}
printf("Do you want to guess another number? ");
scanf( "%s", &PlayAnother);
if (PlayAnother != 'Y' && PlayAnother != 'y')
{
printf("Thank you for playing the guessing game.\n\n");
CanExit = 1;
}
}

}