Guessing game

The below code will generate a guessing game.

Logic 

Store a number in an variable.This will be the hidden number.If the user enters number which is greater or smaller then the hidden number then display an appropriate message.Limit the user to fixed number of tries so that the game can end if the user is unable to guess the hidden number.


Code : 

#include <stdio.h>
#include <conio.h>

void main()

{
    int x,i,j,num,count;
    printf("Welcome...\nMax number of tries is 4");
    count=0;
    x=37;    //this is the value which is to be guessed

    for(i=1;i!=x;i)

    {
        printf("\nEnter number:");
        scanf("%d",&i);
        if(i>x)
            printf("Too Large");
        if(i<x)
            printf("To Small");
        count++;
        if(count==4)
            break;
    }

    if(count==4)

        printf("\n\nYou lose\nnumber of tries:%d",count);
    else
        printf("\n\nYou win\nnumber of tries:%d",count);

    getch();

}

1 comments:

Online casino games | William Hill | Better Business Bureau
Welcome to Online Casino | William Hill Online Casino | William Hill™ Casino - Visit our website 라이브 바카라 사이트 to play your favourite games.‎Payment Methods · ‎Payment Methods · ‎Payment Methods · ‎Sports

Reply

Post a Comment

CodeNirvana
Newer Posts Older Posts
© Copyright Encyclopedia of C | Designed By Code Nirvana
Back To Top