Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,844 questions

51,765 answers

573 users

How to write the guess my birthday day game in C

1 Answer

0 votes
#include <stdio.h> 

int main(void)
{   
    int bd_day = 27;	
    int guess, max = 31, min = 1, i = 0;	

    printf("You  have 3 times to try\n");
    while (i++ < 3)
    {
         printf("Guess the day of my Birthday (1-31): ");
		 scanf("%d",&guess);

		 if (guess == bd_day)
		 {
		 		 printf("You Win!\n");
		 }
		 else if (guess < min)
         {
		 		 printf("Day is between 1 to 31\n");
		 }
		 else if (guess > max)
		 {
		 		 printf("Day is between 1 to 31\n");
		 }
		 else if (guess > bd_day)
		 {
		 		 printf("Too High\n");
		 }
		 else if (guess < bd_day)
		 {
		 		 printf("Too Low\n");	
		 }
		 else
		 {
		 		 printf("Try again!\n");	
		 }
    }
    return 0;
}

 
/*
run:
   
You  have 3 times to try
Guess the day of my Birthday (1-31): 3
Too Low
Guess the day of my Birthday (1-31): 30
Too High
Guess the day of my Birthday (1-31): 27
You Win!

*/


 



answered Nov 1, 2016 by avibootz
edited Nov 1, 2016 by avibootz
...