| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 853 人关注过本帖
标题:又要麻烦高手们了~~~自己写的一个小程序,不知道错在哪里
只看楼主 加入收藏
tiw
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2008-2-13
收藏
 问题点数:0 回复次数:6 
又要麻烦高手们了~~~自己写的一个小程序,不知道错在哪里
#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]]
搜索更多相关主题的帖子: 麻烦 
2008-03-23 16:35
moonwalker
Rank: 1
等 级:新手上路
威 望:1
帖 子:909
专家分:2
注 册:2007-3-2
收藏
得分:0 
你的变量名和函数名重了,编译器自然报错了,year和week,换个函数名

“视频教程网”免费提供教学资源
C不限制你的自由!
条件是自己承担滥用自由的恶果!
2008-03-23 16:47
zhuwei168
Rank: 1
来 自:东软信息学院
等 级:新手上路
帖 子:180
专家分:0
注 册:2008-2-13
收藏
得分:0 
你那些的函数好像都重复了耶
2008-03-23 16:59
tiw
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2008-2-13
收藏
得分:0 
哦,谢谢~~~~~~~~~~
2008-03-23 19:32
hyq1122
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2008-3-24
收藏
得分:0 
函数是不能做为参数的
1、int  week(int year(),int week)//计算当天星期
{   int a;
    a=year()+week;
    return a;
}
,这段中把year()做为参数,其实是错误的,你不能把函数作为参数,如果要把函数作为参数,请使用“指向函数的指针”。这道题目里面,不用把这个year()函数作为参数,直接调用就可以,而且计算的时候a=year()+week;少了参数。2、main()函数的函数名写错了,你写的是mian
2008-03-25 09:36
kissme
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-4-21
收藏
得分:0 
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)
2008-03-25 11:49
tiw
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2008-2-13
收藏
得分:0 
这个程序经过大家的帮助,可以运行了,但算法上有点问题!~~~
2008-03-25 19:06
快速回复:又要麻烦高手们了~~~自己写的一个小程序,不知道错在哪里
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018716 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved