Tuesday, March 16, 2010

A guessing game in C

#include
#include
#include

void main()
{
int num,guess=-1,tries=0,pass=0;
time_t t;
srand((unsigned)time(&t));
num=rand()%100;
clrscr();
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!!!\nYou won!!!!!!!!!!1 ");
pass=1;
goto a;
}
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);
a:
getch();
}

No comments:

Post a Comment