check this out.. this is one way of doing it.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#define RANGE 100
#define TRIES 6
int rnd(int range);
void seedrnd(void);
void main()
{
int guessme, guess, t;
char again[4];
do
{
seedrnd();
guessme = rnd(RANGE) + 1;
printf("GUESS!?!\nGuess the random number.\n");
printf("I'm thinking of a number between 1 and %i.\n",RANGE);
printf("Can you guess it in %i tries?\n",TRIES);
for(t = 1; t <= TRIES; t++)
{
printf("Guess #%i:",t);
scanf("%i", &guess);
fflush(stdin);
if(guess == guessme)
{
printf("You got it!\n");
break;
}
else if(guess < guessme)
{
printf("Too low!\n");
}
else
{
printf("Too high!\n");
}
}
printf("The answer was %i.\n\n",guessme);
printf("Play again ? ");
fgets(again, sizeof(again), stdin);
} while(toupper(again[0]) == 'Y');
}
int rnd(int range)
{
int r;
r = rand() % range;
return(r);
}
void seedrnd(void)
{
srand((unsigned)time(NULL));
}