Click here to Skip to main content
12,956,410 members (77,878 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
hello everyone,
i had a project to make an astrological signs program ive done every thing:
main ()
{
    int day, month; //declaring whole number (variable)
    print_heading (); // Calling function " print_heading "
    
    printf(" enter your day and month of birth\n" );
    scanf("%d/%d", &day , &month);
		
    if ((month == 1 && day >= 20) || (month == 2 && day <= 18))
	printf("You are a Aquarius.\n" "you are Witty,Clever,Humanitarian,Inventive,Original.\n""but you are aslo Stubborn,Unemotional,Sarcastic,Rebellious,Aloof.\n");
 
    if ((month == 2 && day >= 19) || (month == 3 && day <= 20))
        printf("You are a Pisces.\n""Compassionate, Adaptable, Accepting, Devoted, Imaginative.\n""but you are also Oversensitive,Indecisive, Self-pitying, Lazy, Escapist.\n");
 
    if ((month == 3 && day >= 21) || (month == 4 && day <= 19))
        printf("you are a Aries.\n""you are  Independent, Generous, Optimistic, Enthusiastic, Courageous.\n""but you are also  Moody, Short tempered, Self-involved, Impulsive, Impatient.\n");
   
    if ((month == 4 && day >= 20) || (month == 5 && day <= 20))
	    printf("you are a Taurus.\n""you are  Dependable, Persistent, Loyal, Patient, Generous.\n""but you are also  Stubborn, Laziness, Possessive, Materialistic, Self-indulging.\n");
	
    if ((month == 5 && day >= 21) || (month == 6 && day <= 20))
        printf("you are a Gemini.\n""you are  Energetic, Clever, Imaginative, Witty, daptable.\n""but you are also Superficial, Impulsive, Restless, Devious, Indecisive.\n");
    
    if ((month == 6 && day >= 21) || (month == 7 && day <= 22))
	    printf("you are a Cancer.\n""you are  Loyalty, Dependable, Caring, Adaptable, Responsive.\n""but you are also  Moody, Clingy, Self-pitying, Oversensitive, Self-absorbed.\n");
	
    if ((month == 7 && day >= 23) || (month == 8 && day <= 22))
	    printf("you are a Leo.\n""you are  Confident, Ambitious, Generous, Loyal, Encouraging.\n""but you are also Pretentious, Domineering, Melodramatic, Stubborn, Vain.\n");	    
	
    if ((month == 8 && day >= 22) || (month == 9 && day <= 23))
	    printf("you are a Virgo.\n""you are  Analytical, Observant, Helpful, Reliable, Precise.\n""but you are also  Skeptical, Fussy, Inflexible, Cold, Interfering.\n");
	
    if ((month == 9 && day >= 23) || (month == 10 && day <= 22))
	    printf("you are a Libra.\n""you are  Diplomatic, Graceful, Peaceful, Idealistic, Hospitable.\n""but you are also Superficial, Vain, Indecisive, Unreliable.\n");
	
    if ((month == 10 && day >= 23) || (month == 11 && day <= 21))
	    printf("you are a Scorpio\n""you are  Loyal, Passionate, Resourceful, Observant, Dynamic\n""but you are also Jealous, Obsessive, Suspicious, Manipulative, Unyielding\n");
	
    if ((month == 11 && day >= 22) || (month == 12 && day <= 21))
	    printf("you are a Sagittarius.\n""you are Independence.\n""but you are also Unemotional.\n");
	
    if ((month == 12 && day >= 22) || (month == 1 && day <= 19))
	    printf("you are a Capricorn.\n""you are responsible, patient, ambitious, resourceful, loyal.\n""but you are also dictatorial, inhibited, conceited, distrusting, unimaginative.\n");
        
    printf("\n\n");
            
    printf("Press ENTER a few times to terminate the program");
    fflush(stdout);
    getchar(); getchar(); getchar(); getchar();
    getchar(); getchar(); getchar(); getchar();
    return 0;
    
}

now when i enter like 35/6 it should give me error but instead it tells me that you are a Gemini.
how to make it just for the proper days of the month .
thanks in advance.
Posted 19-Apr-12 0:25am
Updated 19-Apr-12 0:35am
Jochen Arndt185.1K
v2
Comments
Jochen Arndt 19-Apr-12 6:36am
   
Reformatted question (removed enclosing blockquotes).

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You should validate the pair {day, month} immediately after the user inputs them, you may use, for instance (warning, not tested), the following function:
// returns 1 on successfull validation
//         0 otherwise
int validate(int day, int month)
{
  if (day < 1) return 0;
  switch ( month )
  {
  case 1:
  case 3:
  case 5:
  case 7:
  case 8:
  case 10:
  case 12:
    if (day > 31) return 0;
    break;
  case 4:
  case 6:
  case 9:
  case 11:
    if (day > 30) return 0;
    break;
   case 2:
    if (day > 29) return 0; // we allow 29th of february, year is unknown...
    break;
  default:
    return 0;
  }
  return 1;
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,869
CHill60 3,550
Maciej Los 3,302
ppolymorphe 2,080
Jochen Arndt 1,973


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 19 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100