Latest Movie :
Home » , » Guessing Game In C

Guessing Game In C

{[['']]}

This is a small guessing game written in C. In this guessing game you have to guess a number between 0 & 100. You have 8 chances to do that. Every time you guess wrongly the program will give you a hint that your guess is too high or your guess is too low. Based on this hint you have to guess the number in the remaining attempts. Here’s the code
 
#include<stdio.h>
#include<stdlib.h>
#include<time.h> void main()
{
int num,guess=-1,tries=0,pass=0;
time_t t;
srand((unsigned)time(&t));
num=rand()%100;
while((guess!=num)&&tries<8)
{
printf(“Enter the guess num b/w 0 & 100 (you have %d tries left out)\n”,(8-tries)); scanf(“%d”,&guess);
tries++;
if(guess==num)
{
printf(“Hurray you guessed it correctly!!!\n”);
pass=1;
}
else if(num< guess)
printf(“Your guess is too high\n”);
else
printf(“Your guess is too low\n”);
}
if(pass==0)
printf(“Sorry you lost! The correct number is %d\n”,num);
}
Share this article :

Post a Comment

Feel Free to Say thanks Comment Here

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. SoftwareLibrary4u - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger