当前位置: 代码迷 >> C语言 >> 又要麻烦高手们了~~~自己写的一个小程序,不知道错在哪里
  详细解决方案

又要麻烦高手们了~~~自己写的一个小程序,不知道错在哪里

热度:217   发布时间:2008-03-23 16:35:22.0
又要麻烦高手们了~~~自己写的一个小程序,不知道错在哪里
#include<stdio.h>
int b(long year, long presentyear,int month,int day)//计算天数
{  int sum=0,leap=0;
   if(month==2&&day==29)
  {
      if(presentyear%400==0||(presentyear%4==0&&presentyear%100!=0))
   {
      while((presentyear+=4)<=year)
    {
        sum+=5;
    }
    return sum;
   }
   else
   {
       printf("had not the day!\n");
       return -10;
   }

  }
  else if(month==1||(month==2&&(day!=29)))
  {
     while(presentyear++<year)
   {

   if(presentyear%400==0||(presentyear%4==0&&presentyear%100!=0))/*判断是不是闰年*/
leap=1;
else
leap=0;
if(leap==1)/*如果是闰年,应该多1天*/
sum+=2;
else
sum+=1;
}

return sum;
}
  else
  {
    while((presentyear+=1)<=year)
   {

   if(presentyear%400==0||(presentyear%4==0&&presentyear%100!=0))/*判断是不是闰年*/
leap=1;
else
leap=0;
if(leap==1)/*如果是闰年,应该多1天*/
sum+=2;
else
sum+=1;
}

return sum;

}
}

int  c(int week,long year,long presentyear,int month,int day)//计算当天星期
{   int n;
    n=b(year,presentyear,month,day)+week;
    return n;
}




void main()
{   int presentyear,age,year,presentage,month,day,week,flag;
    printf("this program gives your age in a year ,and your birthday week in that year\n");
    printf("what year is this?\n");
    scanf("%d",&presentyear);
    printf("which year you want know?\n");
    scanf("%d",&year);
    printf(" what is your present age?\n");
    scanf("%d",&presentage);
    printf("what is month and day\n");
    scanf("%d%d",&month,&day);
    printf("what is your birthday (month,day)and which week in that day?\n");
    printf("monday=1\ttuesday=2\twednesday=3\tthusday=4\tfriday=5\tsturday=6\tsunday=7\n");
    scanf("%d",&week);
    age=year+presentage-presentyear;
    printf("you well be %d year in the %d\n",age ,year);
    printf("your birthday month %d day %d is \n",month,day);
    flag=c(week,year,presentyear,month,day);
    switch(flag%7)
    {   case 0:printf("%d\n",7);break;
        case 1:printf("%d\n",1);break;
        case 2:printf("%d\n",2);break;
        case 3:printf("%d\n",3);break;
        case 4:printf("%d\n",4);break;
        case 5:printf("%d\n",5);break;
        case 6:printf("%d\n",6);break;
        default:printf("error!\n");break;
     }


}

[[it] 本帖最后由 tiw 于 2008-5-29 16:26 编辑 [/it]]
搜索更多相关的解决方案: 麻烦  

----------------解决方案--------------------------------------------------------
你的变量名和函数名重了,编译器自然报错了,year和week,换个函数名
----------------解决方案--------------------------------------------------------
你那些的函数好像都重复了耶
----------------解决方案--------------------------------------------------------
哦,谢谢~~~~~~~~~~
----------------解决方案--------------------------------------------------------
函数是不能做为参数的
1、int  week(int year(),int week)//计算当天星期
{   int a;
    a=year()+week;
    return a;
}
,这段中把year()做为参数,其实是错误的,你不能把函数作为参数,如果要把函数作为参数,请使用“指向函数的指针”。这道题目里面,不用把这个year()函数作为参数,直接调用就可以,而且计算的时候a=year()+week;少了参数。2、main()函数的函数名写错了,你写的是mian
----------------解决方案--------------------------------------------------------
int year(int presentyear,int year)//计算天数
{  int days=0;
   while(presentyear<=year)
   {  if(leap(presentyear)==0) //没有申明函数。
      days+=365;
      else
      days+=366;
      presentyear++;

   }

return days%7;

}
int leap(int year)//计算是否是闰年 //把这个函数放到最上面去
{  int leap;
   if((year%4==0&&year%100!=0)||year%400==0)
   leap=1;
   else
   leap=0;
   return leap;
}
在调用这个函数之前都没有申明leap()。。 if(leap(presentyear)==0)
----------------解决方案--------------------------------------------------------
这个程序经过大家的帮助,可以运行了,但算法上有点问题!~~~
----------------解决方案--------------------------------------------------------
  相关解决方案