| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 496 人关注过本帖
标题:编译错误
只看楼主 加入收藏
ahyshong
Rank: 2
等 级:论坛游民
帖 子:28
专家分:86
注 册:2009-2-14
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:3 
编译错误
一个人从1990.1.1号开始打渔,三天打鱼,两天晒网,问到指定的某一天他是在打渔还是晒网?
#include<stdio.h>
struct date{
    int year;
    int month;
    int day;
};

void main()
{
    struct date today,term;
    int days(struct day);
    int yearday,year,day;
    printf("Enter year/month/day:");
    scanf("%d%d%d",&today.year,&today.month,&today.day);
    term.month=12;
    term.day=31;
    for(yearday=0,year=1990;year<today.year;year++){
        term.year=year;
        yearday+=days(term);          /*计算从1990年至指定年的前一年共有过少天*/
    }
    yearday+=days(today);             /*加上制定年到指定日期的天数*/
    day=yearday%5;                      /*求余数*/
    if(day>0&&day<4)printf("He was fishing at that day.\n");
    else printf("He was sleeping at that day.\n");
}

int days(struct day)
struct date day;
{
    static int day_tab[2][13]=
    {{0,31,28,31,30,31,30,31,31,30,31,30,31,},     /*非闰年*/
    {0,31,29,31,30,31,30,31,31,30,31,30,31,},      /*闰年*/
    };
    int i,lp;
    lp=day.year%4==0&&day.year%100!=0||day.year%400==0;
    for(i=1;i<day.month;i++)
        day.day+=day_tab[lp][i];
    return(day.day);
}
编译不能通过,那位大侠看看帮解决一下。谢谢
搜索更多相关主题的帖子: 编译 
2010-04-14 10:43
mywaylgh
Rank: 8Rank: 8
来 自:厨房
等 级:蝙蝠侠
威 望:5
帖 子:188
专家分:729
注 册:2010-3-10
收藏
得分:15 
int days(struct day);
汗...函数不是你这样申明和调用的

#include<stdio.h>
struct date{
    int year;
    int month;
    int day;
};
int days(date day);//函数申明
int main()
{
    struct date today,term;
    int days(struct day);
    int yearday,year,day;
    printf("Enter year/month/day:");
    scanf("%d%d%d",&today.year,&today.month,&today.day);
    term.month=12;
    term.day=31;
    for(yearday=0,year=1990;year<today.year;year++){
        term.year=year;
        yearday+=days(term);          /*计算从1990年至指定年的前一年共有过少天*/
    }
    yearday+=days(today);             /*加上制定年到指定日期的天数*/
    day=yearday%5;                      /*求余数*/
    if(day>0&&day<4)printf("He was fishing at that day.\n");
    else printf("He was sleeping at that day.\n");
}

int days(date day)
//struct date day;  这个就不要了
{
    static int day_tab[2][13]=
    {{0,31,28,31,30,31,30,31,31,30,31,30,31,},     /*非闰年*/
    {0,31,29,31,30,31,30,31,31,30,31,30,31,},      /*闰年*/
    };
    int i,lp;
    lp=day.year%4==0&&day.year%100!=0||day.year%400==0;
    for(i=1;i<day.month;i++)
        day.day+=day_tab[lp][i];
    return(day.day);
}

帮你改的.. 看红色的部分

人生就像茶几 上面放着许多杯具

人生也像厨房 里面总有一些洗具
2010-04-14 10:58
ahyshong
Rank: 2
等 级:论坛游民
帖 子:28
专家分:86
注 册:2009-2-14
收藏
得分:0 
以下是引用mywaylgh在2010-4-14 10:58:51的发言:
非常感谢啊,第一次真的用结构体来解决问题,知道怎么用了。谢谢谢谢
2010-04-14 11:04
liyang04300
Rank: 2
等 级:论坛游民
帖 子:75
专家分:94
注 册:2010-3-17
收藏
得分:0 
#include<stdio.h>
struct date
{
    int year;
    int month;
    int day;
};
date.day(year)
{
    static int day_tab[2][13]=
    {{0,31,28,31,30,31,30,31,31,30,31,30,31,},     /*非闰年*/
    {0,31,29,31,30,31,30,31,31,30,31,30,31,},      /*闰年*/
    };
    int i,lp,day.day;
    day.day=0;
    lp=day.year%4==0&&day.year%100!=0||day.year%400==0;
    for(i=1;i<day.month;i++)
        day.day+=day_tab[lp][i];
    return(day.day);
}
struct date today,term;
int main()
{   int yearday;
    printf("Enter year/month/day:");
    scanf("%d%d%d",&today.year,&today.month,&today.day);
    term.month=12;
    term.day=31;
    yearday=0;
    for(year=1991;year<today.year;year++)
    {
        date.day(year)
        yearday+=date.day(year);          /*计算从1990年至指定年的前一年共有过少天*/
    }
    yearday+=days(today);             /*加上制定年到指定日期的天数*/
    day=yearday%5;                      /*求余数*/
    if(day>0&&day<4)
    printf("He was fishing at that day.\n");
    else
    printf("He was sleeping at that day.\n");
}
2010-04-14 14:38
快速回复:编译错误
数据加载中...
 
   



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

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