| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1003 人关注过本帖
标题:菜菜鸟 终于写出来了..大家帮我看看有没有改进的地方!谢谢自由人生
取消只看楼主 加入收藏
剁吧剁吧
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2008-5-2
收藏
 问题点数:0 回复次数:2 
菜菜鸟 终于写出来了..大家帮我看看有没有改进的地方!谢谢自由人生
代码如下:

/****该函数判断输入是否为闰年并且判断日期是否输入正确****/

#include <stdio.h>

void main()
{
    int year=0;
    int monch=0;
    int day=0;

    while(1)
    {
        printf("请输入生日(格式1988-06-18):");
        scanf("%d-%d-%d",&year,&monch,&day);
        fflush(stdin);

        if((year>=1900 && year<=2000))
        {
            if((year%4==0&&year%100!=0)||year%400==0)
            {
                printf("%d年是闰年\n",year);
                if(monch==1||monch==3||monch==5||monch==7||monch==8||monch==10||monch==12)
                {
                    printf("%d月有31天\n",monch);
                    if(day<=31&&day>=1)
                    {
                        printf("日期输入正确\n");
                        return;
                    }
                    else
                        printf("日期输入错误\n");
                }
                else
                    if(monch==4||monch==6||monch==9||monch==11)
                    {
                        printf("%d月有30天\n",monch);
                        if(day<=30&&day>=1)
                        {
                            printf("日期输入正确\n");
                            return;
                        }
                        else
                            printf("日期输入错误!\n");
                    }
                else
                    if(monch==2)
                    {
                        printf("%d月有29天\n",monch);
                        if(day<=29&&day>=1)
                        {
                            printf("日期输入正确\n");
                            return;
                        }
                        else
                            printf("日期输入错误!\n");
                    }

                else
                    if(monch>12||monch<0)
                        printf("月份输入错误!\n");
            }
            else
            {
                printf("%d年不是闰年\n",year);
                if(monch==1||monch==3||monch==5||monch==7||monch==8||monch==10||monch==12)
                {
                    printf("%d月有31天\n",monch);
                    if(day<=31&&day>=1)
                    {
                        printf("日期输入正确\n");
                        return;
                    }
                    else
                        printf("日期输入错误!\n");
                }
                else
                    if(monch==4||monch==6||monch==9||monch==11)
                    {
                        printf("%d月有30天\n",monch);
                        if(day<=30&&day>=1)
                        {
                            printf("日期输入正确\n");
                            return;
                        }
                        else
                            printf("日期输入错误\n");
                    }
                else
                    if(monch==2)
                    {
                        printf("%d月有28天\n",monch);
                        if(day<=28&&day>=1)
                        {
                            printf("日期输入正确\n");
                            return;
                        }
                        else
                            printf("日期输入错误!\n");
                    }
                else
                    if(monch>12||monch<0)
                        printf("月份输入错误!\n");
            }
        }
        else    
            printf("你输入的年份错误!\n");        
    }
}

[[it] 本帖最后由 剁吧剁吧 于 2008-5-3 03:05 编辑 [/it]]
搜索更多相关主题的帖子: 菜菜 人生 自由 改进 
2008-05-03 03:04
剁吧剁吧
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2008-5-2
收藏
得分:0 
[bo]以下是引用 [un]starwing[/un] 在 2008-5-3 06:37 的发言:[/bo]

#define _IS_LEAP_YEAR(y)        (((y % 4 == 0) && (y % 100 != 0)) || \
                                ((y + 1900) % 400 == 0))
上面是从VC的crt源文件中抽出来的一个宏,不好怎么评价,但既然是微软的东西,自然 ...



复制你的代码出错 用VC++6.0 编译出现6个错误

错误1:未定义的 IsLeap和IsDateVaild  前面你用 bool 我不明白是什么意思 请指教?
错误2:为定义的 false和true   返回真和假的意义在哪里我有点不明白
2008-05-03 12:47
剁吧剁吧
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2008-5-2
收藏
得分:0 
while (getchar()!='\n'); 这个语句我也没有学 虽然知道 getchar()!='\n' 是个条件 但是不明白是什么意思..刚刚百度了下 不是很明白
2008-05-03 13:01
快速回复:菜菜鸟 终于写出来了..大家帮我看看有没有改进的地方!谢谢自由人生
数据加载中...
 
   



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

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