Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C++/CLI C
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
Edited 19-Apr-12 0:35am
v2
Comments
Jochen Arndt at 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
0 OriginalGriff 693
1 George Jonsson 345
2 BillWoodruff 337
3 Sergey Alexandrovich Kryukov 244
4 Garth J Lancaster 240
0 Sergey Alexandrovich Kryukov 10,764
1 Maciej Los 5,474
2 OriginalGriff 5,472
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web03 | 2.8.141030.1 | Last Updated 19 Apr 2012
Copyright © CodeProject, 1999-2014
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