Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 19-Apr-12 0:35am
v2
Comments
Jochen Arndt 19-Apr-12 6:36am    
Reformatted question (removed enclosing blockquotes).

1 solution

You should validate the pair {day, month} immediately after the user inputs them, you may use, for instance (warning, not tested), the following function:
C
// 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;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900