Techiio-author
Started by Anik AdhikaryMay 12, 2022

Open
How to write a program in c to create a number guessing game ?

2 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 2 VIEWES SHARE

please someone help me, I can't understand in what logic I can do this ?

1 Replies

Techiio-commentatorSidhdarth Basu replied 3 months ago0 likes0 dislikes
#include <stdio.h>
int main()
{
    int num, guess, tries = 0;
    srand(time(0)); /* seed random number generator */
    num = rand() % 100 + 1; /* random number between 1 and 100 */
    printf("Guess My Number Game\n\n");
    do
    {
        printf("Enter a guess between 1 and 100 : ");
        scanf("%d", &guess);
        tries++;
        if (guess > num)
        {
            printf("Too high!\n\n");
        }
        else if (guess < num)
        {
            printf("Too low!\n\n");
        }
        else
        {
            printf("\nCorrect! You got it in %d guesses!\n", tries);
        }
		
    }while (guess != num);
    return 0;
}
You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance