帮助C编程 [英] help in the c programing

查看:79
本文介绍了帮助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;
    
}


现在,当我输入像35/6时,它应该给我错误,但它却告诉我您是双子座.
如何只在一个月的适当日子里制作.


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.

推荐答案

您应该在用户输入{{c0>,month}对后立即验证它们,例如,可以使用(警告,未经测试),以下功能:
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;
}


这篇关于帮助C编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆