/* Random Number Guessing Game : Ask user to guess a number,
if user corrects correct then user wins, else asks to continue
the game till user wins and count in how many times user guessed
correctly. */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int r, num, count = 1, dummy;
srand(time(NULL));
r = rand() % 100;
do{
printf("Guess a number between 0 and 100: ");
scanf("%d", &num);
if(num > r)
printf("Too High !!!");
else if(num < r)
printf("Too Low !!!");
else if(r == num){
printf("Hurray !!! You win.....\nYou guesses correct in %d times.\n", count);
exit(0);
}
printf("\nPress '0' to guess again: ");
scanf("%d", &dummy);
if(dummy == 0)
count++;
}while(dummy == 0);
return 0;
}
Comments
Post a Comment