Random number Generator problem
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int number, guess, n_guess = 1;
srand(time(0));
number = rand() % 100 + 2;
// printf("The random number is %d \n", number);
do
{
printf("Enter the guess number from 2-100 : \n");
scanf("%d", &guess);
if (guess < number)
{
printf("Please Enter Higher Number! \n");
}
else if (guess > number)
{
printf("Please Enter Lower Number ! \n");
}
else
{
printf("You Guessed at %d attempts \n", n_guess);
}
n_guess++;
} while (guess != number);
return 0;
}
No comments:
Post a Comment