| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1968 人关注过本帖
标题:调用函数返回值出错了!怎么办?
只看楼主 加入收藏
落翼天玑乱
Rank: 1
等 级:新手上路
帖 子:20
专家分:3
注 册:2016-3-7
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:6 
调用函数返回值出错了!怎么办?
#include <stdio.h>

      void panduan(int year,int month,int day);
   
    int main ()
    {
                printf("---------输入年月日,计算星期几!---------\n\n\n");
        while(1)
        {
            while(1)
            {
                int year,month,day;
                int y,m,d,c,s,w;
                int i=0;
                printf("请输入年月日(示例:2016 3 15):");
                scanf("%d %d %d",&year,&month,&day);
                printf("\n");
               
                y=year;m=month;d=day;
               
                if(panduan(y,m,d))
                {
                    printf("日期不存在!请重新输入!\n\n");break;
                 }
                 
        
                 
                if (m==1) c=d;
                else if (m==2) c=31+d;
                else if (m==3) c=31+28+d;
                else if (m==4) c=31+28+31+d;
                else if (m==5) c=31+28+31+30+d;
                else if (m==6) c=31+28+31+30+31+d;
                else if (m==7) c=31+28+31+30+31+30+d;
                else if (m==8) c=31+28+31+30+31+30+31+d;
                else if (m==9) c=31+28+31+30+31+30+31+31+d;
                else if (m==10) c=31+28+31+30+31+30+31+31+30+d;
                else if (m==11) c=31+28+31+30+31+30+31+31+30+31+d;
                else if (m==12) c=31+28+31+30+31+30+31+31+30+31+30+d;
               
                if (m>2)
                {if (y%100==0) {if (y%400==0) c=c+1;}
                else if (y%4==0) c=c+1;}
                s=(y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400+c;
                w=s%7;
               
                printf("\n");
                switch (w)
                {
                case 0: printf("           %d年%d月%d日是星期日\n",year,month,day);break;
                case 1: printf("           %d年%d月%d日是星期一\n",year,month,day);break;
                case 2: printf("           %d年%d月%d日是星期二\n",year,month,day);break;
                case 3: printf("           %d年%d月%d日是星期三\n",year,month,day);break;
                case 4: printf("           %d年%d月%d日是星期四\n",year,month,day);break;
                case 5: printf("           %d年%d月%d日是星期五\n",year,month,day);break;
                case 6: printf("           %d年%d月%d日是星期六\n",year,month,day);break;
                    
                }
                printf("\n\n");
            }   
        }
        
        return 0;
    }





    void panduan(int year,int month,int day)
    {
        int i;
        if(year<=0)
        {
            i=1;
        }
        
        if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
        {
            if(day<=0||day>31)
            {
                i=1;
            }
        }else if(month==4||month==6||month==9||month==11)
        {
            if(day<=0||day>30)
            {
                i=1;
            }
        }else if(month==2)
        {
            if(day%4==0&&day%100!=0)
            {
                if(day<=0||day>29)
                {
                    i=1;
                }
            }else
            {
                if(day<=0||day>28)
                {
                    i=1;
                }
            }
            
        }else
        {
            i=1;
        }
        return i;
        
    }
搜索更多相关主题的帖子: include 年月日 
2016-04-03 21:23
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:5 
  int panduan(int year,int month,int day)  //void???
    {
        int i=0; //???
        if(year<=0)
        {
            i=1;
        }
        
        if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
        {
            if(day<=0||day>31)
            {
                i=1;
            }
        }else if(month==4||month==6||month==9||month==11)
        {
            if(day<=0||day>30)
            {
                i=1;
            }
        }else if(month==2)
        {
            if(year%400==0||(year%4==0&&year%10!=0))  //year
            {
                if(day<=0||day>29)
                {
                    i=1;
                }
            }else
            {
                if(day<=0||day>28)
                {
                    i=1;
                }
            }
            
        }else
        {
            i=1;
        }
        return i;        
    }

   唯实惟新 至诚致志
2016-04-03 23:24
初学李阳
Rank: 2
来 自:江西新余
等 级:论坛游民
帖 子:6
专家分:10
注 册:2016-3-28
收藏
得分:5 
回复 楼主 落翼天玑乱
把函数void返回类型改成int试试
2016-04-03 23:28
初学李阳
Rank: 2
来 自:江西新余
等 级:论坛游民
帖 子:6
专家分:10
注 册:2016-3-28
收藏
得分:0 
回复 楼主 落翼天玑乱
改了就行了,编译通过

#include <stdio.h>

      int panduan(int year,int month,int day);

    int main ()
    {
                printf("---------输入年月日,计算星期几!---------\n\n\n");
        while(1)
        {
            while(1)
            {
                int year,month,day;
                int y,m,d,c,s,w;
                int i=0;
                printf("请输入年月日(示例:2016 3 15):");
                scanf("%d %d %d",&year,&month,&day);
                printf("\n");

                y=year;m=month;d=day;

                if(panduan(y,m,d))
                {
                    printf("日期不存在!请重新输入!\n\n");break;
                 }



                if (m==1) c=d;
                else if (m==2) c=31+d;
                else if (m==3) c=31+28+d;
                else if (m==4) c=31+28+31+d;
                else if (m==5) c=31+28+31+30+d;
                else if (m==6) c=31+28+31+30+31+d;
                else if (m==7) c=31+28+31+30+31+30+d;
                else if (m==8) c=31+28+31+30+31+30+31+d;
                else if (m==9) c=31+28+31+30+31+30+31+31+d;
                else if (m==10) c=31+28+31+30+31+30+31+31+30+d;
                else if (m==11) c=31+28+31+30+31+30+31+31+30+31+d;
                else if (m==12) c=31+28+31+30+31+30+31+31+30+31+30+d;

                if (m>2)
                {if (y%100==0) {if (y%400==0) c=c+1;}
                else if (y%4==0) c=c+1;}
                s=(y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400+c;
                w=s%7;

                printf("\n");
                switch (w)
                {
                case 0: printf("           %d年%d月%d日是星期日\n",year,month,day);break;
                case 1: printf("           %d年%d月%d日是星期一\n",year,month,day);break;
                case 2: printf("           %d年%d月%d日是星期二\n",year,month,day);break;
                case 3: printf("           %d年%d月%d日是星期三\n",year,month,day);break;
                case 4: printf("           %d年%d月%d日是星期四\n",year,month,day);break;
                case 5: printf("           %d年%d月%d日是星期五\n",year,month,day);break;
                case 6: printf("           %d年%d月%d日是星期六\n",year,month,day);break;

                }
                printf("\n\n");
            }
        }

        return 0;
    }





    int panduan(int year,int month,int day)
    {
        int i;
        if(year<=0)
        {
            i=1;
        }

        if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
        {
            if(day<=0||day>31)
            {
                i=1;
            }
        }else if(month==4||month==6||month==9||month==11)
        {
            if(day<=0||day>30)
            {
                i=1;
            }
        }else if(month==2)
        {
            if(day%4==0&&day%100!=0)
            {
                if(day<=0||day>29)
                {
                    i=1;
                }
            }else
            {
                if(day<=0||day>28)
                {
                    i=1;
                }
            }

        }else
        {
            i=1;
        }
        return i;

    }
2016-04-03 23:31
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
除了逻辑上的问题,main里面的两个while不是死循环?

   唯实惟新 至诚致志
2016-04-03 23:33
xmzyjr
Rank: 1
等 级:新手上路
帖 子:9
专家分:8
注 册:2015-11-21
收藏
得分:5 
你这题大概是输入几年几月几日 然后输出是几天吧  你可是定义个数组s[12]={31,28,31,30,31,30,31,31,30,31,30,31};还有闰年的s[12]={31,29,31,30,31,30,31,31,30,31,30,31}; 先判断是否为闰年 然后几月 把数组的几月前的天全部加起来 然后再加上当天的 那就是总共的天数  若是星期几的话那就是取余了
2016-04-03 23:35
mk_zhou
Rank: 2
来 自:历代兵家必争之地
等 级:论坛游民
威 望:1
帖 子:78
专家分:83
注 册:2015-6-30
收藏
得分:5 
程序代码:
//代码里有三个问题,
//第一个:void panduan(int year,int month,int day);   把void改为int;
//第二个:while 存在死循环,去除最外围的while循环;
//第三个:void panduan(int year,int month,int day);中 i没有进行初始化,定义i的时候需要将i的值初始化为0;

#include <stdio.h>

      //void panduan(int year,int month,int day);
   int panduan(int year,int month,int day);
    int main ()
    {
                printf("---------输入年月日,计算星期几!---------\n\n\n");
       // while(1)     //死循环
         //   {

            while(1)
            {
                int year,month,day;
                int y,m,d,c,s,w;
                int i=0;
                printf("请输入年月日(示例:2016 3 15):");
                scanf("%d %d %d",&year,&month,&day);
                printf("\n");
               
                y=year;m=month;d=day;
               
                if(panduan(y,m,d))
                {
                    printf("日期不存在!请重新输入!\n\n");break;
                 }
                
       
                
                if (m==1) c=d;
                else if (m==2) c=31+d;
                else if (m==3) c=31+28+d;
                else if (m==4) c=31+28+31+d;
                else if (m==5) c=31+28+31+30+d;
                else if (m==6) c=31+28+31+30+31+d;
                else if (m==7) c=31+28+31+30+31+30+d;
                else if (m==8) c=31+28+31+30+31+30+31+d;
                else if (m==9) c=31+28+31+30+31+30+31+31+d;
                else if (m==10) c=31+28+31+30+31+30+31+31+30+d;
                else if (m==11) c=31+28+31+30+31+30+31+31+30+31+d;
                else if (m==12) c=31+28+31+30+31+30+31+31+30+31+30+d;
               
                if (m>2)
                {if (y%100==0) {if (y%400==0) c=c+1;}
                else if (y%4==0) c=c+1;}
                s=(y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400+c;
                w=s%7;
               
                printf("\n");
                switch (w)
                {
                case 0: printf("           %d年%d月%d日是星期日\n",year,month,day);break;
                case 1: printf("           %d年%d月%d日是星期一\n",year,month,day);break;
                case 2: printf("           %d年%d月%d日是星期二\n",year,month,day);break;
                case 3: printf("           %d年%d月%d日是星期三\n",year,month,day);break;
                case 4: printf("           %d年%d月%d日是星期四\n",year,month,day);break;
                case 5: printf("           %d年%d月%d日是星期五\n",year,month,day);break;
                case 6: printf("           %d年%d月%d日是星期六\n",year,month,day);break;
                   
                }
                printf("\n\n");
            }   
        //}
       
        return 0;
    }





    //void panduan(int year,int month,int day)
    int panduan(int year,int month,int day)
    {
        //int i;
        int i=0;  //i需要进行初始化
        if(year<=0)
        {
            i=1;
        }
       
        if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
        {
            if(day<=0||day>31)
            {
                i=1;
            }
        }else if(month==4||month==6||month==9||month==11)
        {
            if(day<=0||day>30)
            {
                i=1;
            }
        }else if(month==2)
        {
            if(day%4==0&&day%100!=0)
            {
                if(day<=0||day>29)
                {
                    i=1;
                }
            }else
            {
                if(day<=0||day>28)
                {
                    i=1;
                }
            }
           
        }else
        {
            i=1;
        }
        return i;
       
    }
我总结了一下~~~

仰望星空,看看有没有馅饼落下
2016-04-04 01:48
快速回复:调用函数返回值出错了!怎么办?
数据加载中...
 
   



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

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