game-guess a number between 1 and 100

 #include <stdio.h>

#include <stdlib.h>
#include <time.h>
int main()
{

    int i = 1, num, gnum;
    srand(time(0));
    num = rand() % 100 + 1;

    do
    {
        printf("Guess the number between 1 and 100:\n");
        scanf("%d", &gnum);
        if (gnum < num)
        {
            printf("Enter a higher number\n");
        }
        else if (gnum > num)
        {
            printf("Enter a lower number\n");
        }
        else
        {
            printf("You guessed the number in %d attempts", i);
        }

        i++;
    } while (num != gnum);

    return 0;
}

Comments