Number guessing game(Project 1)

 #include <stdio.h>

#include <stdlib.h>
#include <time.h>
void main()
{
    printf("Welcome to the Number Guessing Game\n");
    printf("Are you ready to play the game.\n");
    printf("If yes then enter 1 if no then enter anything beside 1\n");
    int c;
    scanf("%d", &c);
    if (c == 1)
    {
        printf("The number is between 1-100\n");
        int n, t,count=0;
        srand(time(0));
        n = rand() % 100 + 1; //Generates a random number between 1 to 100
        do
        {
            printf("Guess the number:");
            scanf("%d", &t);
            if(t>n)
            {
                count++;
                if(t<n+10)
                printf("Guessed number is slightly bigger\n");
                if(t>n+10)
                printf("Guessed number is bigger\n");
                continue;
            }
            if(t<n)
            {
                count++;
                if(t>n-10)
                printf("Guessed number is slightly smaller\n");
                if(t<n-10)
                printf("Guessed number is smaller\n");
                continue;
            }
            if(t==n)
            {
                printf("Yay Congrats you guessed the number\n");
                printf("Number of tries you took: %d\n",count);
            }
        } while (t != n);
    }
    else 
    printf("Hope you play soon :(");
}

Comments