| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4159 人关注过本帖
标题:关于switch中的default,为什么我定义的default不起作用啊
取消只看楼主 加入收藏
lusan168
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-11-17
收藏
 问题点数:0 回复次数:1 
关于switch中的default,为什么我定义的default不起作用啊
#include<stdio.h>
void main()
{
 int year,month,day;
 int leap;
 printf("please input year,month,day:");
 scanf("%d%d%d",&year,&month,&day);
 switch(month)
 {
  case 12:
   day+=30;
  case 11:
   day+=31;
  case 10:
   day+=30;
  case 9:
   day+=31;
  case 8:
   day+=31;
  case 7:
   day+=30;
  case 6:
   day+=31;
  case 5:
   day+=30;
  case 4:
   day+=31;
  case 3:
   day+=28;
  case 2:
   day+=31;
  case 1:
   day=day;
  default:
   printf("please input error:\n");
   break;
 }
   
 if((year%400==0 || year%4==0 &&year%100!=0) && month>2)
  leap=1;
 else
  leap=0;
 if(leap=1 && month>2)
  day++;
 printf("\nday=%d\n",day);
  
}
搜索更多相关主题的帖子: switch default 定义 
2007-11-26 23:23
lusan168
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-11-17
收藏
得分:0 
回复 1# 的帖子
#include<stdio.h>
void main()
{
    int year,month,day;
    int leap;
    printf("please input year,month,day:");
    scanf("%d%d%d",&year,&month,&day);
    switch(month)
    {
        case 12:
            day+=30;
        case 11:
            day+=31;
        case 10:
            day+=30;
        case 9:
            day+=31;
        case 8:
            day+=31;
        case 7:
            day+=30;
        case 6:
            day+=31;
        case 5:
            day+=30;
        case 4:
            day+=31;
        case 3:
            day+=28;
        case 2:
            day+=31;
        case 1:
            day=day;break;
        default:
            printf("sorry,please input error!\n");
        
    }
    if(month>=1 && month<=12){
    if((year%400==0 || year%4==0 &&year%100!=0) && month>2)
        leap=1;
    else
        leap=0;
    if(leap=1 && month>2)
        day++;
    printf("\nday=%d\n",day);
    }
    else
        printf("\nbyebye\n");
        
}
2007-11-26 23:42
快速回复:关于switch中的default,为什么我定义的default不起作用啊
数据加载中...
 
   



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

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